Are view controllers with nib files broken in ios 8 beta 5?

前端 未结 7 1906
囚心锁ツ
囚心锁ツ 2020-12-01 21:46

I created a test project in ios 8 beta 4 which as a main view controller and a second view controller created as a UIViewController subclass with a xib file.

I put a

7条回答
  •  失恋的感觉
    2020-12-01 22:03

    This trick works for me. If you have a base view controller class you can override the nibName property returning the class name (equals to the xib file name).

    class BaseViewController: UIViewController {
    
       override var nibName: String? {
          get {
             guard #available(iOS 9, *) else {
                let nib = String(self.classForCoder)
                return nib
             }
    
             return super.nibName
           }
        }
    }
    

    All view controllers that inherit from this base class could load their xib. e.g. MyViewController: BaseViewController could load MyViewController.xib

提交回复
热议问题