您是否熟悉viewWillAppear,viewDidAppear,viewDidLoad,viewWillDisappear和viewDidDisappear?
在此之前,让我问您viewWillAppear
, viewDidAppear
, viewDidLoad
, viewWillDisappear
和viewDidDisappear
的运行顺序是什么?
如果您知道答案,请关闭此网页并进行游戏。 🙂
因此,编写了一个简单的片段代码来验证这一点:
Example code:
运行结果:
2017-04-14 08:18:18.923 TestBlock[3940:264012] viewDidLoad is running
2017-04-14 08:18:18.924 TestBlock[3940:264012] viewWillAppear is running
2017-04-14 08:18:18.946 TestBlock[3940:264012] viewDidAppear is running
2017-04-14 08:18:22.187 TestBlock[3940:264012] viewWillDisappear is running
2017-04-14 08:18:22.689 TestBlock[3940:264012] viewDidDisappear is running
单击按钮后,您将看到顺序:
- viewDidLoad
- viewWillAppear
- viewDidAppear
- viewWillDisappear
- viewDidDisappear