I have a 2 tab iPhone application: the first one downloads images from a web server, parses the data, and then displays it in a CollectionView. Obviously I want to do all the work in the background, and update the UI in the main thread when this is done. The problem is, when I switch to the Camera (Tab #2), I have a black screen preview. I used instruments, read all the threads on SO about this problem, and still can't get it to work. The ONLY way I successfully and permanently solved the problem is to use only the main thread in tab #1 to download, then parse then update UI. Somebody has a clue on what to do here?
This randomly blocks camera:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSOperation *op1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(initialPostLoading) object:@"Op1"];
NSOperation *op2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadSomeBrands) object:@"Op2"];
NSOperation *completion = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"2");
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self.collectionView reloadData];
[HUD show:NO];
[HUD setHidden:YES];
[refreshControl endRefreshing];
NSLog(@"Back in Main Thread");
}];
}];
[completion addDependency:op1];
[completion addDependency:op2];
[queue addOperations:@[op1, op2, completion] waitUntilFinished:NO];
NSLog(@"3");
This doesn't block camera:
[self initialPostLoading];
[self downloadSomeBrands];
[self.collectionView reloadData];