的結束通知我有NSOperationQueue 3 NSInvocationOperation在prepareForSegue回調,我完成所有異步任務後需要移動到另一個視圖控制器。 如何獲得有關在完成所有任務異步,只有在此之後移動到另一個屏幕通知?如何接收上的異步任務
我想這沒有成功:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
});
編輯:
看來,我不明白的東西:
-(void)initPurchase{
[operationQueue cancelAllOperations];
NSInvocationOperation *downloadImageOperation = [[NSInvocationOperation alloc] initWithTarget:[BSImageDownloader getInstance] selector:@selector(downloadImageSync:) object:@"http://.........jpg"];
NSInvocationOperation *createImageOperation = [[NSInvocationOperation alloc] initWithTarget:[BSImageCreator getInstance] selector:@selector(createImage:) object:@"dsadsadsa"];
NSInvocationOperation *saveImageOperation = [[NSInvocationOperation alloc] initWithTarget:[BSImageSaver getInstance] selector:@selector(saveImageAsPng:) object:[BSSharedObject getInstance].createdImage];
[createImageOperation addDependency:downloadImageOperation];
[saveImageOperation addDependency:createImageOperation];
[operationQueue addOperation:downloadImageOperation];
[operationQueue addOperation:createImageOperation];
[operationQueue addOperation:saveImageOperation];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
[[BSPopupManager getInstance]showWaitingPopup];
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
Purchase *purchase = [[Purchase alloc] init];
[purchase initPurchase];
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
[[BSPopupManager getInstance] closeWaitingPopup];
BSPurchaseViewController *purchaseViewController = [segue destinationViewController];
purchaseViewController.pngImage = [BSSharedObject getInstance].createdImage;
NSLog(@"2");
});
dispatch_release(group);
}
}
我仍然得到的NSLog(@ 「2」) ;比我更早的保存圖像中第3 NSInvocationOperation