オブザーバーがこれ以上操作がないことを通知すると、関数は呼び出されません (performSelector...)。面白いことに、NSLog(@"queue has completed") が正しくログに記録されます。
- (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];
}
}
編集
とった:
dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector:@selector(refreshCollectionView) withObject:nil afterDelay:0.2];
});
なぜ performSelectorOnMainThread... が機能しなかったのかわかりませんが、このように機能します。