iOS:如何重用从笔尖构建的 UIView?
情况:
- ReusableView.h
- ReusableView.m
- ReusableView.xib
- ViewController.h
- ViewController.m
- ViewController.xib
ReusableView 是一种基本模板,我想将其用作多个 ViewController 的背景。我尝试使用 ReusableView 作为 ViewControllers 视图,但它没有被加载。我在这里缺少什么?这有可能吗(应该是,不)?
编辑
经过进一步调查,我发现我的 ReusableView 是用 ViewController 实例化的。它可以在 viewDidLoad 中使用。但是在其笔尖中定义的 ReusableView 的 Outlet 未连接。所有 IBOutlet 均为空。
我认为这是因为ReusableViews initWithCoder方法是用ViewController的UINibDecoder调用的。我怎样才能改变这一点?
Situation:
- ReusableView.h
- ReusableView.m
- ReusableView.xib
- ViewController.h
- ViewController.m
- ViewController.xib
ReusableView is kind of basic template that I want to use as background across several ViewControllers. I tried using ReusableView as the ViewControllers view but it does not get loaded. What am I missing here? Is this possible at all (it SHOULD be, no)?
EDIT
After further investigation I found that my ReusableView IS instanciated with ViewController. It is available in viewDidLoad. But the Outlets of the ReusableView that are defined in it's nib are not connected. All IBOutlets are null.
I think this is because the ReusableViews initWithCoder method is called with the UINibDecoder of ViewController. How can I change that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望 ReusableView 作为其他 viewController 的基本模板,那么在这种情况下,您可以从 ReusableView 继承其他视图控制器然后在您创建的所有其他视图控制器中使用
ReusableView
的属性。If you want the
ReusableView
as the base template for the otherviewControllers
, then in that case, you can inherit the other view controllers from theReusableView
and then use the properties of theReusableView
in all of the other view controllers that you have created .