1
當我的觀察員告訴我沒有更多的操作時,函數不會被調用(performSelector ...)。有趣的是,NSLog(@「queue has completed」)被正確記錄。NSOperationQueue完成不會啓動新方法
- (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 ...沒有工作,但它以這種方式工作。
任何建議如何? – user1832330 2013-05-13 22:16:31
得到它,但無論如何不工作:/任何方法不會開始(即使我把refreshCollectionView的東西放入隊列完整語句內) – user1832330 2013-05-13 22:22:53