View inside a view [duplicate]
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?
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.
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.
精彩评论