2012-06-17 153 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 
});