iPhone:在Xib上查看属性,有什么特别的吗?
我不敢相信我被困在这个问题上,但就这样了。
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,Apple 说视图控制器应该用于充满视图的整个屏幕 - (但我猜 iPad 容器视图是不同的)。
我猜您只想一次只使用其中一个视图控制器。在这种情况下,您不应该使用子视图 - 只需以编程方式创建视图控制器,创建视图,将视图分配给视图控制器的视图属性,然后将视图控制器添加到窗口或导航栏。
并且,在您的视图控制器中:
可能是您想要的 - 它允许您在单个视图控制器中使用多个笔尖。
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:
might be what you want - it allows you to use multiple nibs with a single viewcontroller.
在将
viewController.myView1
添加为子视图之前,您可以 NSLog 吗?是否nil
?如果是
nil
,请尝试在addSubview:
方法之前添加此行:[viewController view];
注意:viewController 我所说的是同一个 viewController,它有两个根视图
view
和myView1
。Can you NSLog your
viewController.myView1
before add it as a subview? Is itnil
or not?If it's
nil
, try to add this line before youraddSubview:
method:[viewController view];
Note: The viewController I am talking about is the same viewController which have two root views
view
andmyView1
.你的代码应该很好,因为这相当简单,而且我一直这样做。
只需确保您的插座接线正确,并且您正在合成它们并且它们在您的标头中是公开的。
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.