2012-06-17 152 views
0

在我的應用程序用戶按開始按鈕後,我在for週期執行一些代碼。 如何在此期間讓應用程序負責用戶交互? 在C#中有BackgroundWorker類,在IOS中有沒有類似的東西?在後臺執行任務

+0

看看[調度隊列(http://developer.apple.com/library/ios /#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html) – inwit

回答

1

您可以像這樣使用選擇:

[self performSelectorInBackground:@selector(yourForCycle:) withObject:nil]; 


-(void)yourForCycle:(id)sender { 

    //Your for cycle... 
} 
2

使用gcd上述像下面

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 
dispatch_async(queue,^{ 
    //Put your heavy code here it will not block the user interface 
});