【发布时间】:2016-09-26 04:24:52
【问题描述】:
我已经按照这个link 实现了completionblock
@interface : ParentViewController ()
@property (nonatomic, strong) ChildViewController *childViewController;
@end
在父视图控制器的表视图委托方法(didSelectRowAtIndexPath)中,我添加容器视图如下
- (void) addChildView {
ChildViewController * childViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ChildViewController"];
childViewController.view.frame = (CGRect) {0, 0, self.view.frame.size};
[self addChildViewController:childViewController];
__block ParentViewController *parentViewController = self;
[parentViewController.childViewController setCompletionCallBack:^{
self.childViewController.view.backgroundColor = [UIColor clearColor];
[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^{
self.childViewController.view.frame = (CGRect) {0, 1000, self.view.frame.size};
} completion:^(BOOL finished) {
[self.childViewController.view removeFromSuperview];
self.childViewController = nil;
}];
}];
[self.view addSubview: childViewController.view];
[childViewController didMoveToParentViewController:self];
[UIView animateWithDuration:0.5f animations:^{
childViewController.view.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.15f];
[self.view layoutIfNeeded];
} completion:nil];
}
ChildViewController 的接口和实现
@interface ChildViewController : UIViewController
@property (nonatomic, copy) void (^completionCallBack) ();
@end
- (IBAction)cancelPressed:(id)sender {
self.completionCallBack ();
}
当我尝试在按钮操作中调用 completionCallBack 时,出现访问错误。
我不确定我在这里犯了什么错误,非常感谢任何帮助。
【问题讨论】:
标签: objective-c ios9 objective-c-blocks uicontainerview