Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait until code is done. iOS

I can call some selector by this code

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

and the Thread will wait until this selector is working (if I set waitUntilDone:YES). My question is - Can i wait until some code is done?

for example. I have some subview, which loads with animation. Animation duration is 2 sec. And if i make some actions on background view, while animating, i have an error. I'd like to wait until animation is over. And I can't to make a selector, and use

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

Any suggestions? )

like image 224
Arthur Avatar asked Feb 18 '23 04:02

Arthur


2 Answers

You can try this way

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

And you need to use it as

[self.tableView waitUntilDone:^{
    //call the required method here                                            
}];
like image 192
Anoop Vaidya Avatar answered Feb 22 '23 22:02

Anoop Vaidya


UIView animation gives this to you in the form of the block style animation

[UIView animateWithDuration:0.25f
                 animations:^{
                   // animations
                 } completion:^(BOOL finished) {
                   // run code when the animation is finished
                 }];
like image 29
Paul.s Avatar answered Feb 23 '23 00:02

Paul.s