一、presentingViewController和presentedViewController
@property(nonatomic,readonly) UIViewController *presentingViewController;//present出该控制器的那个控制器
@property(nullable, nonatomic,readonly) UIViewController *presentedViewController;//该控制器present出来的控制器
如果是控制器A present出 控制器B, 也就可以得到:
A.presentedViewController = B ;
B.presentingViewController = A
A和B是相互持有的,因此如果不dismiss是不会释放的。
二、presentViewController和dismissViewController
[self presentViewController:nextVc animated:YES completion:^{
NSLog(@"block将会在nextV显示完毕时调用");
}];
/*
1、presentViewController并没有切换根控制器。发送一个present消息只是将keywindow 的view暂时移除,再将presentedViewController 的view添加到keywindow上;
2、当前控制器发送了presentViewController消息,弹出nextvc. nextvc之所以不会被释放,是因为nextvc被当前控制器的presentedViewController 属性强引用着。
*/
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];//The presenting view controller is responsible for dismissing the view controller it presented.
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"block将在控制器view消失后调用");
}]; // 如果presentedviewcontroler自己调用了这方法,系统会自动让它的presentingviewcontroller去处理dismiss操作。原则上就是"谁污染,谁处理"
参考:https://www.aliyun.com/jiaocheng/397604.html
苹果官方文档:
Declaration
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion;
Discussion
The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
If you want to retain a reference to the view controller'��s presented view controller, get the value in the presented<wbr>View<wbr>Controller
property before calling this method.
The completion handler is called after the view<wbr>Did<wbr>Disappear:
method is called on the presented view controller.
网友评论