2011-03-07 85 views
0

我有一个函数foo()调用后台线程上的功能栏012(g)在调用另一个函数之前做一些事情。 bar()所做的全部都在后台。与此同时,我正在展示ActivityIndi​​cator。一旦我的bar()函数返回,我正在调用一个函数,它会停止MainThread上的stopActivityIndi​​cator。执行在后台和主线程ios

现在,我想在调用stopActivityIndi​​cator()之前调用MainThread中的另一个函数() 我该怎么做? 可以在*之前放置另一个[self performSelectorOnMainThread:@selector(functionIWantToCall:)withObject:nil wailUntilDone:YES]; 吗?

回答

2

你可以派遣一个块主线程上运行,把你需要成块的任何代码:

[[NSOperationQueue mainQueue] addOperationWithBlock:^ { 

    // Code here 
    NSLog(@"This is the main thread"); 

}]; 

使用你的代码,这会成为:

bar() 
{ 
    bar1(); 

    [[NSOperationQueue mainQueue] addOperationWithBlock:^ { 
     [stopActivityIndidator]; 
     [functionIWant]; 
    }]; 
} 
相关问题