我有问题。这种情况是这样的:我得到了一个NSOperationQueue,其中包含需要等待的所有NSOperationQueue:YES。我还需要在队列或操作正在运行时更新UI。处理这种情况的最佳方法是什么?UI没有更新,因为NSOperationQueue waitUntilFinished YES
我已经尝试performSelectorOnMainThread,但每次需要更新UI时都需要使用此方法。这似乎不是一个好的解决方案。
- (void)loadPreviewPageWithMagazineID:(NSString *)magazineID userID:(NSString *)userID {
NSMutableArray *operationArray = [NSMutableArray array];
for (NSInteger i = 1; i <= _numTotalPages; ++i) {
//NSLog(@"currenpage = %d, index = %d",_selectedPage,pageIndex);
NSDictionary *arguments = [NSDictionary dictionaryWithObjectsAndKeys:magazineID,
@"itemID", userID, @"userID", [NSNumber numberWithInt:i],
@"pageNumber", nil];
AFOperation *imageOperation =
[[AFOperation alloc] initWithTarget:self
selector:@selector(savePageToDisk:)
object:arguments];
[imageOperation addObserver:self forKeyPath:@"isFinished" options:0 context:nil];
[imageOperation setUserInfo:arguments];
[operationArray addObject:imageOperation];
[imageOperation release];
}
[_imageQueue addOperations:operationArray waitUntilFinished:YES];
}
- (void)processingMagazine:(NSDictionary *)arguments {
// load pdf document from decrypted data
NSString *userID = [arguments objectForKey:@"userID"];
NSString *magazineID = [arguments objectForKey:@"itemID"];
[self loadPreviewPageWithMagazineID:magazineID userID:userID];
}
所以
[_collectionCoverView performSelectorOnMainThread:@selector(setDownloadProgress:)
withObject:[NSNumber numberWithFloat:progress]
waitUntilDone:YES];
Is there any appropriate way to handle the UI?
你的意思是说你的队列等待直到你更新你的UI? – Vignesh 2012-03-17 05:53:36
队列和UI可以同时运行吗? – Lunayo 2012-03-17 06:07:32
雅。这绝对有可能。这有可能发生。 – Vignesh 2012-03-17 06:08:43