我想分析在其他線程的一些數據(沒有主線程)如何知道其他線程中的任務何時完成?
for (NSString* theKey in [rssSourcesData allKeys])
{
NSURL *url = [NSURL URLWithString:theKey];
NSURLRequest *initialRequest = [NSURLRequest requestWithURL:url];
AFGDataXMLRequestOperation *oper = [AFGDataXMLRequestOperation
XMLDocumentRequestOperationWithRequest:initialRequest
success:^(NSURLRequest *request, NSHTTPURLResponse *response, GDataXMLDocument *XMLDocument) {
[self parseDataInBackground:XMLDocument forKey:theKey];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, GDataXMLDocument *XMLDocument) {
NSLog(@"failure handler: %@",theKey);
}];
[oper start];
}
finshied解析後在其他線程中的所有數據,我想回到回主線程。怎麼做 ?
您可以在代碼中使用塊來強制應用程序返回到主線程。或者,您可以在parseDataInBackground完成時添加偵聽器併發布NSNotification,以便偵聽器可以在之後執行代碼。此鏈接可能有助於理解:http://stackoverflow.com/questions/10492138/ios-what-is-the-equivalent-of-an-event-listener-in-objective-c – faterpig