viewcontroller-lifecyle

viewDidLoad is called twice

↘锁芯ラ 提交于 2019-12-17 20:55:01
问题 My viewDidLoad in a view controller is called twice. Once by [UIViewController View] and a second time by [UINib instanciateWithOwner:Options] . Why is this happening? Can it be prevented? 回答1: Any code you put inside of viewDidLoad should be able to run multiple times with out any issues. If you have code that only needs to run once for your controller use -awakeFromNib. The reason is because the view of the view controller can be unloaded and loaded multiple times. The code inside of

viewDidLoad is called twice

南楼画角 提交于 2019-11-28 13:58:46
My viewDidLoad in a view controller is called twice. Once by [UIViewController View] and a second time by [UINib instanciateWithOwner:Options] . Why is this happening? Can it be prevented? Joe Any code you put inside of viewDidLoad should be able to run multiple times with out any issues. If you have code that only needs to run once for your controller use -awakeFromNib . The reason is because the view of the view controller can be unloaded and loaded multiple times. The code inside of viewDidLoad should only modify the UI to reflect the current state. Now that I got that out of the way, your