在后台执行任务

时间:2012-06-17 19:45:07

标签: objective-c ios

在我的应用程序用户按下开始按钮后,我在for周期执行一些代码。 在此过程中如何让应用程序负责用户交互? 在C#中有BackgroundWorker类,IOS中有类似内容吗?

2 个答案:

答案 0 :(得分: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
});

答案 1 :(得分:1)

你可以使用这样的选择器:

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


-(void)yourForCycle:(id)sender {

    //Your for cycle...
}
相关问题