問題が発生しました。このシナリオは次のようなものです:NSOperationQueueには、waitUntilDone:YESを必要とするさまざまなNSOperationQueueが含まれています。また、キューや操作が実行されているときにUIを更新する必要があります。この状況を処理する最善の方法は何ですか?NSOperationQueue waitUntilFinishedのためUIが更新されませんでした。
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];
}
ので、UIを更新するたびに、私は私はあなたのコードから多くを理解しなかったの
[_collectionCoverView performSelectorOnMainThread:@selector(setDownloadProgress:)
withObject:[NSNumber numberWithFloat:progress]
waitUntilDone:YES];
Is there any appropriate way to handle the UI?
UIを更新するまでキューを待つことを意味しますか? – Vignesh
キューとUIを同時に実行できますか? – Lunayo
Ya。間違いなく可能です。有りうる。 – Vignesh