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

前端 未结 7 1957
囚心锁ツ
囚心锁ツ 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:05

    Here's code, based on Francesco answer. It contains check if nib file exits, so app will not crashed when you load UIViewController which doesn't have associated xib (you can reproduce it on iOS8)

    override var nibName: String? {
        get {
            let classString = String(describing: type(of: self))
            guard nibBundle?.path(forResource: classString, ofType: "nib") != nil else {
                return nil
            }
            return classString
        }
    }
    override var nibBundle: Bundle? {
        get {
            return Bundle.main
        }
    }
    

提交回复
热议问题