What's the difference between custom class and file's owner setting in xib file?

后端 未结 2 505
星月不相逢
星月不相逢 2021-02-01 01:42

In a custom xib file, what\'s the difference between the two following setting methods shown in the images below?

2条回答
  •  野的像风
    2021-02-01 01:55

    When you add custom UIView with XIB you init this custom view in some UIViewController and write:

    let nib = UINib(nibName: "CardView", bundle: nil)
    let view = nib.instantiate(withOwner: self, options: nil).first as! CardView
    

    File's owner (in withOwner: parameter) this is usually owner is a ViewController where you add your custom UIView

提交回复
热议问题