简体   繁体   中英

Block not getting called from method

I'm guessing my syntax is off, but I can't seem to figure this out as I am new to blocks. I have this custom method:

-(void)animateViewConstraintChange: (void(^)(void))completionHandler;

this method looks like this:

-(void)animateViewConstraintChange:(void(^)(void))completionHandler
{
    [[self view]setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.6
                 animations:^{
                 [[self view]layoutIfNeeded];
                 } completion:^(BOOL finished){
                     completionHandler;
                 }];

}

It compiles and runs, however when I call this method and actually put something in for completionHandler, that code doesn't ever get called.

[self animateViewConstraintChange:^{
    [orderedViewControllers removeObject:[self middleViewController]];
    [[[self middleViewController] view] removeFromSuperview];

    [[self middleViewController] removeFromParentViewController];

    _middleViewController = nil;

    [[self view]setNeedsUpdateConstraints];
}];    

So, in the case of the above code, animateViewConstraintChange is called however the code in the block doesn't.

Also, the compiler is giving me an error in the animateViewConstraintChange Method at

completionHandler;

saying, "Expression result unused".

Thanks for looking.

Should be calling block with parens:

} completion:^(BOOL finished){
                 completionHandler();
         }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM