Reputation: 138
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.
Upvotes: 1
Views: 624
Reputation: 10065
Should be calling block with parens:
} completion:^(BOOL finished){
completionHandler();
}];
Upvotes: 3