iPhone:在Xib上查看属性,有什么特别的吗?

发布于 2024-11-30 20:05:16 字数 349 浏览 2 评论 0原文

我不敢相信我被困在这个问题上,但就这样了。

我有一个 viewController,我试图通过 addsubview 属性(基本为)将其添加到另一个 viewController,但是我不是在执行 viewController.view,而是在执行 viewController.myView1。

我基本上在 xib 上有 2 个根视图(都带有插座),但是我不想连接 xib 的视图属性,因为我想选择要显示的视图。

我无法让它出现! view 属性是某种特殊的钩子吗?

我不明白为什么 addsubview:mysubview 不应该工作?

一些示例似乎使用了 2 个不同的 xib,但这似乎有点矫枉过正

I can't believe I am stuck on this but here goes.

I have a viewController which I am trying to add to another viewController via the addsubview property (basic as) however I am not doing viewController.view but viewController.myView1.

I basically have 2 root views on the xib (both with outlets) however I don't want to wire up the view property of the xib because I want to choose which view to show.

I can't get it to appear! Is the view property some sort of special hook?

I can't see why addsubview:mysubview should not work?

Some examples seem to use 2 different xib's but that seems a overkill

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

吝吻 2024-12-07 20:05:16

首先,Apple 说视图控制器应该用于充满视图的整个屏幕 - (但我猜 iPad 容器视图是不同的)。

我猜您只想一次只使用其中一个视图控制器。在这种情况下,您不应该使用子视图 - 只需以编程方式创建视图控制器,创建视图,将视图分配给视图控制器的视图属性,然后将视图控制器添加到窗口或导航栏。

并且,在您的视图控制器中:

self = [super initWithNibName:nibOne bundle:nil];

可能是您想要的 - 它允许您在单个视图控制器中使用多个笔尖。

Firstly, Apple say a viewcontroller should be used for a whole screen full of views - (but I guess iPad container views are different).

I guess you're wanting to only use one of the viewcontrollers at once. In which case you shouldn't be using subview - just create the viewcontroller programmatically, create the view, assign the view to the viewcontroller's view property and then add the viewcontroller to the window or navigation bar.

and, in your viewcontroller:

self = [super initWithNibName:nibOne bundle:nil];

might be what you want - it allows you to use multiple nibs with a single viewcontroller.

心病无药医 2024-12-07 20:05:16

在将 viewController.myView1 添加为子视图之前,您可以 NSLog 吗?是否nil

如果是 nil,请尝试在 addSubview: 方法之前添加此行:

[viewController view];

注意:viewController 我所说的是同一个 viewController,它有两个根视图 viewmyView1

Can you NSLog your viewController.myView1 before add it as a subview? Is it nil or not?

If it's nil, try to add this line before your addSubview: method:

[viewController view];

Note: The viewController I am talking about is the same viewController which have two root views view and myView1.

離人涙 2024-12-07 20:05:16

你的代码应该很好,因为这相当简单,而且我一直这样做。
只需确保您的插座接线正确,并且您正在合成它们并且它们在您的标头中是公开的。

Your code should be good as this is fairly simple and I do it all the time.
Just make sure your outlets are wired properly and that you are synthesizing them and that they are public in your header.

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