2013-03-13 51 views
3

我可以通过这个代码如何等待代码完成。 iOS的

[self performSelector:<#(SEL)#> onThread:<#(NSThread *)#> withObject:<#(id)#> waitUntilDone:<#(BOOL)#>] 

调用一些选择和线程将等到这个选择是工作(如果我设置waitUntilDone:YES)。我的问题是 - 我可以等到一些代码完成吗?例如

。我有一些子视图,加载动画。动画持续时间是2秒。如果我在背景视图上做一些动作,同时动画,我有一个错误。我想等到动画结束。我不能做出选择,并使用

[self performSelector:<#(SEL)#> onThread:<#(NSThread *)#> withObject:<#(id)#> waitUntilDone:<#(BOOL)#>] 

有什么建议吗? )

回答

5

你可以试试这个方法

-(void)waitUntilDone:(void(^)(void))waitBlock { 
    //use your statement or call method here 
    if(waitBlock){ 
     waitBlock(); 
    } 
} 

而你需要用它作为

[self.tableView waitUntilDone:^{ 
    //call the required method here            
}]; 
+0

谢谢你的形式,它的工作原理 – Arthur 2013-03-13 11:30:16

1

等待直到动画被完成&然后做的事休息:

对于如:

[UIView animateWithDuration:duration 
    animations:^ 
    { 
     //DO ANIMATION ADJUSTMENTS HERE 
    } 
    completion:^(BOOL finished) 
    { 
     //ANIMATION DID FINISH -- DO YOUR STUFF 
    }]; 
2

UIView动画给出了这样您在块风格的动画

[UIView animateWithDuration:0.25f 
       animations:^{ 
        // animations 
       } completion:^(BOOL finished) { 
        // run code when the animation is finished 
       }];