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

99封情书 提交于 2019-12-03 06:20:59

问题


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


回答1:


please check this link : What is the File's Owner (in Interface builder)? confused difference between Custom Class for an Object and for the File's Owner and steps via IB

in first screen shot : you should set the custom class of your View .

and in the second screen shot (files owner) you can Set the file's owner to your UIView subclass so that you can connect outlets to it




回答2:


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



来源:https://stackoverflow.com/questions/34894563/whats-the-difference-between-custom-class-and-files-owner-setting-in-xib-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!