The following code is blocking UI (can't tap another tab until images finish loading).
I have verified it is the UIImage *imageToShow = [[UIImage alloc] initWithData:data];
call that is the culprit by commenting that line out and keeping the download (which I know happens asynchronously and calls completion handler on main thread).
In the case where only the initWithData:
line is commented, the UI response is fine. But how can that line be the line holding up the UI if it is clearly dispatched in background?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
...
[objectStore getFileInContainer:@"public_images" filename:filename completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
UIImage *imageToShow = [[UIImage alloc] initWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
collectionImageView.image = imageToShow;
});
});
}];
...
}