来自插座的自定义 UIView
我知道这个问题已经讨论过很多次了,但我在解决这个问题时仍然遇到一些问题,所以任何帮助将不胜感激。我有一个 MyView 类,它是 UIView 的子类。到目前为止一切顺利,在这个自定义类中,我基本上配置了布局、UI 等。
现在,我有一个单独的 UIViewController,我想要做的是为该自定义视图创建一个出口。在视图控制器的 Nib 中,我将视图的类设置为自定义视图的类并将其连接到插座,但除了空白视图之外我看不到任何内容。
如何以及在哪里从笔尖加载视图?我只是说 self.theOutletForMyCustomView = 从 nib 加载还是别的什么?感谢您的帮助
I know this has been discussed a number of times but I still have some problems getting around the problem, so any help would be appreciated. I have a class MyView which subclasses UIView. So far so good, in this custom class I basically configure the layout, UI, etc.
Now, I have a separate UIViewController and what I want to do is create an outlet for that custom view. In the view controller's Nib I set the view's class to that of my custom view and connect it to the outlet, but I can't see anything apart from a blank view.
How and where do I load the view from nib? Do I simply say self.theOutletForMyCustomView = load from nib or is it something else? Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须在
UIViewController
nib 文件中设置CustomView
的名称,如下然后,您必须在
UIViewController 界面
中保留您的属性:或者
ivar
应该可以工作,但是分配
IBOutlet 属性
不起作用。如果您在
CustomView 类实现
中自定义您的CustomView
。请注意在awakeFromNib
或initWithCoder:
而不是initWithFrame:
中进行初始化First of all, you have to set the name of your
CustomView
inside yourUIViewController
nib file like thatThen, you have to retain your property like that inside your
UIViewController interface
:or an
ivar
should work, butassign
anIBOutlet property
doesn't work.And if you customize your
CustomView
inside yourCustomView class implementation
. Beware of doing your initialization inawakeFromNib
orinitWithCoder:
instead ofinitWithFrame: