当我的观察者告诉我没有更多操作时,不会调用函数(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... 没有工作,但它是这样工作的。