Clean way to force view to load subviews early

前端 未结 6 1056
南方客
南方客 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:32

    merged Rudolph/Swany answers for pre ios9 deployment targets

        if #available(iOS 9.0, *) {
            loadViewIfNeeded()
        }
        else {
            // _ = self.view works but some Swift compiler genius could optimize what seems like a noop out
            // hence this perversion from this recipe http://stackoverflow.com/questions/17279604/clean-way-to-force-view-to-load-subviews-early
            view.alpha = 1
        }
    

提交回复
热议问题