您应该使用委托。当您单击 中的按钮时ReviewViewController
,您会调用如下方法:[self.delegate hideReviewController:self];
这种方法看起来像:
- (void)hideReviewController:(ReviewViewController *)controller {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
controller.view.alpha = 0;
} completion:^(BOOL finished) {
[self.view removeSubview:controller.view];
// If you want the Review Controller to be deallocated:
[self removeChildViewController:controller];
}];
}
编辑:
在您的 ReviewDelegate.h 文件中添加:
@class ReviewViewController;
@protocol ReviewDelegate <NSObject>
- (void)hideReviewController:(ReviewViewController *)controller;
@end
然后添加这个属性:
@property (nonatomic, weak) id <ReviewDelegate> delegate;
在父类中:
- (IBAction)btnReview:(id)sender
{
ReviewViewController *vc = [[ReviewViewController alloc]initWithNibName:@"ReviewViewController" bundle:nil];
vc.delegate = self;
[self addChildViewController:vc];
[vc didMoveToParentViewController:self];
[self.view addSubview:vc.view];
}
- (void)hideReviewController:(ReviewViewController *)controller {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
controller.view.alpha = 0;
} completion:^(BOOL finished) {
[self.view removeSubview:controller.view];
// If you want the Review Controller to be deallocated:
[self removeChildViewController:controller];
}];
}
我还建议您阅读有关委派的内容