Multiple Taps on UICollectionView Cells
January 30, 2014
I have been working on an iOS app at work for a few months now and it is coming close to completion.
Problem:
The issue I had today was that multiple taps on a single or many UICollectionView
Cells would cause the my app to freeze. I narrowed down the issue to be the syncWithServer method I use with the StackMob iOS SDK (Update: StackMob was shutdown in 2014). This method supposedly runs in the background, but I found with many taps in a short amount of time, it got overloaded (comments on why are welcome). The weird thing is that I have a UITableView
with a very similar implementation and it does not run into this issue. The reason being, UITableView
decides not to handle any taps over one at a time, without doing some trick. So I chose a similar solution to fix the issue mentioned above.
Solution:
After trying a timer and custom background queue workaround, I simply tried to disable user interaction with the collection view until the completion callback for the syncWithServer method started. This is seemed to work fine, but I chose to go with the better design choice and put the good ol’ MBProgressHUD. The bonus that comes with that is the fact that it disables interaction with the current view while it is up. This worked well in my favor because then I just needed the following two lines of code:
[AppDelegate showGlobalProgressHUDWithTitle:@"Updating..."];
[AppDelegate dismissGlobalHUD];
Those helper methods, of course, are from the following StackOverflow post. I’m sure there are some downsides to the Global Progress HUD since it is not run on a background thread, but it works well. I was able to dismiss the HUD because of an NSNotifcation
posted from the syncWithServer Completion block. Those two line (in different locations of course) fixed my issue and keeps my app from freezing.
Thanks for reading! I look forward to more posts.
Tweet