views:

473

answers:

1

Nearly all the UINavigationController examples out there show the use of initWithNibName:bundle: to load a NIB containing NOT an entire UIViewController (or subclass) but just a UIView, with the NIB's File's Owner Class property set to UIViewController (or the appropriate subclass) and its view outlet pointed at the UIView.

Why is this? Why can you not instantiate a full UIViewController (in particular, a UITableViewController) from a secondary NIB? And why do you even need to set the view outlet in IB? I don't understand the point of creating a blank white view which is going to be entirely ignored by a UITableViewController anyway.

In the MainWindow NIB, you can do both of the things that you seemingly can't do from a secondary NIB. You can setup a UINavigationController, and then within that you can setup a UITableViewController (or subclass). And you don't need to create an entirely superflous UIView object - rather helpful, since the whole point (I thought!) of a UITableViewController is that it creates and manages an associated table view for you using its delegate methods.

What is going on here? Am I being stupid? Is there some other way of doing what I want to? Or is there some logical reason for things being the way they are?

+3  A: 

In IB create a new "Empty" nib and drag a "Table View Controller" into it from the Library.

Or am I misunderstanding the question?

zaph
Hey zaph. It is easy enough to do as you suggest, but a lot more difficult (for me at least) to then make use of the resulting NIB file.Specifically, when I run the following line of code...UITableViewController *mySecondaryTableViewController = [[UITableViewController alloc] initWithNibName:@"SecondaryTableViewController" bundle:nil];...I get the following error in the console:'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SecondaryTableViewController" nib but the view outlet was not set.'
kennethmac2000
initWithNibName:bundle: expects a NIB containing a UIView. I don't want to create a NIB with a UIView though, since my controller is a UITableViewController which will create a UITableView itself.So how do I actually turn the NIB file containing a Table View Controller (as you suggested I create) into a programatically addressable UITableViewController?
kennethmac2000
EX: [[NSBundle mainBundle] loadNibNamed:@"LapC" owner:self options:nil];
zaph
Thank you, thank you, thank you. :)
kennethmac2000