Clean way to force view to load subviews early

前端 未结 6 1094
南方客
南方客 2021-01-07 23:06

Recently I wrote some code where I tried to refer to an outlet on a UIViewController I\'d just instantiated with [storyboard instantiateViewControllerWith

6条回答
  •  滥情空心
    2021-01-07 23:30

    Not sure how much cleaner this way, but it still works fine:

    _ = vc.view
    

    UPD: for your convenience, you can declare extension like below:

    extension UIViewController {
        func preloadView() {
            let _ = view
        }
    }
    

    You can read explaination by following URL: https://www.natashatherobot.com/ios-testing-view-controllers-swift/

提交回复
热议问题