[英]ViewdidLoad called every time
Why every time I change UIViewController embed in UINavigationController using show push in storyboard ViewDidLoad is called? 为什么每次我使用情节提要中的show push更改嵌入在UINavigationController中的UIViewController时,都会被调用?
It hasn't to be called only once or I have to check programmatically if it is already loaded? 它不是只能被调用一次,还是必须以编程方式检查它是否已加载?
Another relative question: 另一个相对的问题:
In the following best practices found here in StackOverflow that user are talking about init method, but if my ViewController are loaded by storyboard where I have to initialise my properties? 在StackOverflow的以下最佳实践中,用户正在谈论init方法,但是如果我的ViewController是由情节提要加载的,则必须在其中初始化我的属性?
Best practices 最佳实践
Remember not to do view controller initialisation in viewDidLoad. 切记不要在viewDidLoad中进行视图控制器初始化。 This is a common mistake. 这是一个常见的错误。 For stuff that should only happen once when the view controller is loaded, do it in one of the controller's init methods. 对于仅在加载视图控制器时才发生的事情,请使用控制器的init方法之一进行操作。
viewDidLoad
is called first time when the viewController's view is loaded, (either by accessing the view controller's view or by presenting a view controller via modal presentation or via a push presentation). viewDidLoad
在第一次加载viewController的视图时被调用(通过访问视图控制器的视图或通过模态表示或通过推送表示来表示视图控制器)。 Once the view controller is loaded, viewDidLoad will not get called again. 加载视图控制器后,将不会再次调用viewDidLoad。 If you want to use init method, you need to use initWithCoder
for the things that are from storyboard. 如果要使用init方法,则需要将initWithCoder
用于情节提要中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.