简介
在开发中调用
[self presentViewController:vc animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
的时候有点好奇两个VC的生命周期,所以记录下
实现
present
那么在打开VC A的时候,A的生命周期为:
A:viewDidLoad
A:viewWillAppear
A:viewDidAppear
在A中调用方法:
SecondViewController *vc = [SecondViewController new];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:YES completion:nil];
那么A,B的生命周期为:
//先是load B
B:viewDidLoad
//B加载完之后调用A的willDisappear
A:viewWillDisappear
//之后调用B的willAppear和DidAppear
B:viewWillAppear
B:viewDidAppear
//在B didAppear之后再调用A的viewDidDisappear
A:viewDidDisappear
dismiss
在B中调用方法:
[self dismissViewControllerAnimated:YES completion:nil];
那么A,B的生命周期为:
//和A跳B的方法一样,只不过Bdissmiss的话A不用重新load
B:viewWillDisappear
A:viewWillAppear
A:viewDidAppear
B:ViewDidDisappear