简体   繁体   English

每次调用ViewdidLoad

[英]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.

相关问题 实际上,每次有segue转换时都会调用viewDidLoad - viewDidLoad is in fact called every time there is a segue transition 在UIImagePickerController()的dismiss()之后每次调用viewDidLoad()。 - viewDidLoad() is called every time after dismiss() of UIImagePickerController() viewDidLoad中的代码每次调用时都会运行 - Code in viewDidLoad runs every time it is called 每次将子级添加到firebase数据库时,都会调用viewDidLoad - viewDidLoad getting called every time a child is added to firebase database 每次在xCode 9.4和iOS 11中调用的ViewDidLoad()方法 - ViewDidLoad() method called every time in xCode 9.4 and iOS 11 每次调用popViewControllerAnimated后都会调用viewDidLoad: - viewDidLoad getting called every time after calling popViewControllerAnimated: 每次加载viewDidLoad - viewDidLoad loads every time ViewDidLoad第二次未调用Xcode - ViewDidLoad is not called for the second time Xcode 每当我从一个视图到另一个视图进行模态调整时,是否都会调用viewdidload方法? - Does every time I modal from a vie to another view the method viewdidload gets called? TabBar项,应用启动时调用的每个viewDidLoad - TabBar Item, every viewDidLoad called when app launch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM