2016-08-05 52 views
0

我有以下场景:我想在后台线程上多次调用方法,但返回的值来自委托方法,我认为这在主线程上调用。我如何处理后台线程?从主线程上的委托方法接收答案

NSOperationQueue *operationQueue = [NSOperationQueue new]; 
for (int i = 0 ; i < 100; i++) { 
    NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{ 
     [self.routingService calculateRoute:self.routeSettings]; 
    }]; 
    [self.operationQueue addOperation:blockOperation]; 
} 

//Delegate method 
- (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation *)routeInformation { 

    //Here I want to process routeInformation 
} 

请帮帮我。 :)

回答

1

你可以这样做你内心的委托方法

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    //add your processing code here 
}); 
+0

谢谢你的回答,但似乎并没有工作:( – Ovidiu

0
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    //add your background processing code here 

dispatch_async(dispatch_get_main_queue(), ^{ 
//add processing on main thread 
});