开发者

Can viewDidLoad be called mutiple times?

开发者 https://www.devze.com 2023-04-13 08:05 出处:网络
The documentation says \"This method is called after the view controller has loaded its associated views into memory.\"My questions are:

The documentation says "This method is called after the view controller has loaded its associated views into memory." My questions are:

1) if I initialize a view controller is viewDidLoad called, or does the view actually have to be added as a superview of the current view for it to be called

2) If I add the view controllers view, and viewDidLoad is called, then I remove开发者_运维问答 the view controllers view, then re-add it again later, will viewDidLoad be called again?


viewDidLoad is called whenever the view is loaded. This happens when the vc.view property is accessed. It typically happens right before adding the view to a view hierarchy, but it can happen earlier if the property is accessed earlier.

If you remove your view from a view hierarchy, and then a memory warning happens and viewDidUnload is called, then viewDidLoad will be called again if the view property is accessed again. But this is the only way for it to be called a second time; if your view never unloads, then viewDidLoad will never be repeated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号