Force viewDidLoad to fire on iOS

梦想的初衷 提交于 2019-11-28 21:15:52

You can just call [viewController view];.

The documentation for UIViewController explains how the view property is lazy-loaded and that viewDidLoad is called after the view is loaded.

In iOS 9, Apple finally fixed this:

// Loads the view controller's view if it has not already been set.
@available(iOS 9.0, *)
public func loadViewIfNeeded()

Swift 2.0, with same result of @Carl Veazey's solution:

let viewController = MyCustomViewController()
_ = viewController.view

You can create a global instance for that controller(May be in AppDelegate) and call the method you want to perform the action for. Then While pushing to that controller don't create a new instance Just use the instance you have created for global use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!