查看视图内部
我想在另一个视图中包含一个带有自己的控制器的子视图。我看到的方法是在代码中调用 addSubview ,但是必须有一种方法可以在界面生成器本身内部完成所有这些操作,而无需在控制器中对其进行编码。
我想要添加的子视图是在它自己的 xib 文件中定义的。
有任何指示如何实现这一点,或者是否可能?
I would like to include a sub view with its own controller inside another view. The way I saw was to call addSubview
in the code, but there's got to be a way to do all of this inside interface builder itself, without coding it up in the controller.
The subview I want to add is defined in it's own xib file.
Any pointers how to accomplish that, or if is at all possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Interface Builder 中,从库中将视图 (UIView) 拖到主窗口下。请注意,在我的 MainWindow.xib 文件中,视图模式 是一个列表,以便可以轻松查看层次结构,并且您可以根据需要添加更多子视图。
In Interface Builder from the Library drag a View (UIView) under you main Window. Notice in my MainWindow.xib file the View Mode is a list so that it's easy to see the hierarchy and you can add more sub views as you need them.
您通常会使用视图控制器从界面构建器中加载外部 NIB。但是,加载后似乎无法引用此 NIB 的视图。
纯粹视觉上似乎不可能将外部视图添加到层次结构中更深的位置。
不过,您可以创建一个类,该类会在
-viewDidLoad:
期间自动加载外部 NIB,并将其添加为其唯一的子级,从而模拟效果。然后只需拖动 UIView 并在将其拖放到场景上时更改其类即可。You would ordinarily use a view controller to load an external NIB from within interface builder. However, it does not seem to be possible to refer to this NIB's view once you've loaded it.
It does not seem to be possible to add the external view to a spot deeper in the hierarchy purely visually.
You could however create a class that would automatically load an external NIB during
-viewDidLoad:
and add it as its one and only child, hence simulating the effect. Then simply drag a UIView and change its class when dropped on the scene.