Force viewDidLoad to fire on iOS

后端 未结 4 973
粉色の甜心
粉色の甜心 2020-12-14 17:41

I have two window app and while I present first window I would like the view in second window to load and prepare content for later in background.

I\'ve tried to use

相关标签:
4条回答
  • 2020-12-14 18:25

    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()
    
    0 讨论(0)
  • 2020-12-14 18:26

    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.

    0 讨论(0)
  • 2020-12-14 18:42

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

    let viewController = MyCustomViewController()
    _ = viewController.view
    
    0 讨论(0)
  • 2020-12-14 18:46

    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.

    0 讨论(0)
提交回复
热议问题