Thursday, April 30, 2020

Create UICollectionView Like Instagram When Exploring Photos


Hello guys, I hope you're doing well. I was doing research about how to make my UICollectionView like Instagram. As you can see on picture above. I have time to search on the internet but somehow I want to custom it by myself. I mean I don't want to use framework.

After I finished my custom UICollectView, I found IGListKit framework for building fast and flexible lists. But I haven't used it Because I think it's not for custom layout UICollectionView. But if I have much time maybe I will try to use that framework. I think it's cool to use framework that's built by iOS Instagram Developer.

What I want to share is a  custom class UICollectionViewLayout called SavedCollectionViewLayout. Because I used this class to show my saved collection photos. But you can edit the name as you want, no problem at all. But I think there's a room for improvement this class. If you have any idea to improve this code. Tell me. I'm glad I have someone to improve my code quality.

Saturday, April 25, 2020

Make Difference between Double Tap and Single Tap in UIView


Hello guys, today I want to talk about Tap in iOS. Of course in swift because Objective-C now is less used for iOS Developer. If we see Instagram app, we can tap an image with double tap. After that an event has occured. If it's in Instagram we can have an event which is we like that photo with heart animation color changed.

If we single tap, it doesn't do nothing in photo but in video we can play the sound of the video. But if we double tap it, the sound would not interrupted by first tap. If we don't set something in iOS code, we can see interrupting happened.

Fortunately we can handle it easily in coding with swift. It just need one line of code to avoid interrupting single tap. But first make sure we have added two gesture recognizer. UITapGestureRecognizer is the class we need it to set. Don't worry I give you an example below.

Friday, April 17, 2020

Be Careful with "UI API called on a background thread"


After maybe one months I'm quarantined, It's so bored to be at home without doing anything. Luckily I have projects to do. And Of course to write post for this ungapps blog. Today I'm glad I can write to make my english writting better. I think day after day my english gets better haha. Yes honestly I still used google translate to translate some vocabularies that I literally have forgotten.

Today, I want to dig a little bit deeper about Thread in iOS Swift. We need to learn this thing. Because It's very important when we're doing UI think with other thread like downloading video. Because if you don't pay attentation enough, your app would be like freeze in a moment. And It's very bad for User Experience.

Luckily Xcode helps us to catch something that's not right. It would show message like title above "UI API callend on a background thread" in a specific line of code. To do that you need Runtime API Checking is ticked. Edit Scheme->Run (Debug)->Diagnostics->Runtime API Checking. By default it should've been ticked.

Sunday, April 12, 2020

How to cache image for temporary use iOS Swift 5


Welcome back to my blog, this week I was too busy to do so many things. I've almost forgot to post new article this week. So I look my old problem that I've already solved and found a problem how to cache image for get dynamic height of UITableview.

I have a problem to reuse UITableViewCell for inserting the height of each cell. I want my cell to display flexible height for UIImageView. And the image itself is fetched from API server which is to need internet to get it and it's not from local. Sometimes it takes a long time to get big size image.

For the very first time to open an app. It will be harder to cache all of images. So if the user doesn't have good internet connection. Cache all of images is good solution, but it will not automatically resolve our issues. For me there's still a little issue when I want to make my height of UIImageView flexible in UITableView. If I already get the height of image, I need to reload the spesific of uitableview row. And it will make weird for UX.

Wednesday, April 1, 2020

Fix "Attempted to call -cellForRowAtIndexPath: on the table view while it was in the process of updating its visible cells, which is not allowed"


Hello guys, Today the title is a little bit long. Because I want to make the title can be searched exactly the same on google searching. This is a warning not a error. So It wouldn't impact to your app if you run it on your device or emulator. The warning appeared on console not in Buildtime as usually in issue navigator.

This warning doesn't give the exact line number where the warning happened. So we need to do breakpoint to check where it's supposed to be. But the warning in console give us a hint. We take the keyword "cellForRowAtIndexPath". So it related to UITableview because "cellForRowAt" is the method that's in UITableVIew.

As you can see my screenshoot of my console above, there's multiple times the warnings happened. It's because of "cellForRow" called many times, not just once. But don't be deceipted to assume that the warning happed in cellForRow method. The warning actually happened in "heightForRowAt", when in the method, it called dequeueReusableCell, the method of UITableview. As you can see in example below.