tags:

views:

32

answers:

2

Is there anything special I need to do when adding a UIViewController into a nib? My -viewDidLoad method is not being called, even though the nib is being loaded and its subclass is set in IB to my view controller class.

http://dl.dropbox.com/u/448021/Test.zip

There's my test case. I just can't figure out why FooViewController -viewDidLoad isn't being called.

Thanks for the help.

A: 

The FooViewController you created there serves no purpose, if I see things correctly. In MainWindow.xib, you have a navigation controller and your own RootViewController. So far so good. You define the view of that in RootViewController.xib. Also ok. But the View Controller inside that last xib will do nothing, until you do something like

[self.navigationController pushViewController:detailViewController animated:YES];

(which is in your didSelectRowAtIndexPath)

The commented out part in didSelectRowAtIndexPath basically invokes a new viewcontroller when a user selects a row, and does so while loading the associated xib file, which is loaded in this line:

DetailViewController *detailViewController = [[DetailViewController alloc]
                                              initWithNibName:@"Nib name" bundle:nil];

You could also create the viewcontroller in a nib file, like you have now, but then you would need to define an

IBOutlet FooViewController *fooVC;

and link that up within IB, and then push this fooVC onto the view stack when the user selects something - in that case you would skip the alloc / init line above.

mvds
A: 

Add a view to FooViewController. Just go to interface builder and drag a view to FooViewController.

domino