Search code examples
iphoneiosmodel-view-controllerinterface-builderoutlet

iPhone Interface Builder make a view a subView


I have a UIView and a UITableView in the same NIB file like so:enter image description here

I have realised that I can't add a toolbar or anything to this because it has to be a subview to a UIView first. At the current point in time this is merely a separate UITableView. How do I turn it into a subview of the UIView?

Also, if I can't do that, how do I add a new UITableView as a subview of the UIView? I have tried to do so as well and I ended up with the following error: enter image description here

I don't quite know how to add the view outlet as simply dragging the view towards the file's owner does not allow me to do so.

Any help would be much appreciated, thanks in advance.


Solution

  • The easiest way to make a view a subView is by doing it like in the second screenshot. What you are missing is that you need to create a UITableViewController and then in Interface Builder you set the "File Owner" class with the name of your controller in the Identity Inspector. Then you can set the view property to that UITableView.

    File's Owner

    Notice the Custom class of File's Owner