Reputation: 5534
When my observer tells me that there are no more operations, function is not called (performSelector...). Funny thing is that NSLog(@"queue has completed") is logged correctly.
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if (object == self.operationQueue && [keyPath isEqualToString:@"operations"]) {
if ([self.operationQueue.operations count] == 0)
{
[self performSelector:@selector(refreshCollectionView) withObject:nil afterDelay:0.2];
// Do something here when your queue has completed
NSLog(@"queue has completed");
}
}
else {
[super observeValueForKeyPath:keyPath ofObject:object
change:change context:context];
}
}
EDIT
Got it:
dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector:@selector(refreshCollectionView) withObject:nil afterDelay:0.2];
});
Dunno why performSelectorOnMainThread... didnt work but it works this way.
Upvotes: 1
Views: 64
Reputation: 162722
If your observer is being fired on the same thread as the queue, it is quite likely that the queue's thread is being reaped upon completion. Since -performSelector:...afterDelay: requires a running run loop, it is likely dropped on the floor.
Since you are updating the UI anyway, perform that selector on the main thread.
Upvotes: 1