iOS:如何重用从笔尖构建的 UIView?

发布于 2024-12-16 23:02:42 字数 545 浏览 2 评论 0原文

情况:

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2024-12-23 23:02:42

如果您希望 ReusableView 作为其他 viewController 的基本模板,那么在这种情况下,您可以从 ReusableView 继承其他视图控制器然后在您创建的所有其他视图控制器中使用 ReusableView 的属性。

If you want the ReusableView as the base template for the other viewControllers, then in that case, you can inherit the other view controllers from the ReusableView and then use the properties of the ReusableView in all of the other view controllers that you have created .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文