Woodstock
Woodstock

Reputation: 22926

UITableViewController done manually

If I use the Empty template in Xcode, which just gives an app delegate and window, and I want to have a UITableView with navigation bar for drilling up and down, am I correct in assuming I should just do as below, create a UITableView subclass, instantiate it, then instantiate a navController, set the TableView as the navControllers root view and then add the navController as the root view of the Window?

It seems wrong to create a UITableViewController only to add this to another view controller subclass (UINavigationController).

Is this correct?

    MyTableViewController *myTableViewController = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:MyTableViewController];

    [self.window setRootViewController:navController];

Upvotes: 0

Views: 134

Answers (3)

Matt
Matt

Reputation: 2411

You are correct. I'd also recommend you use a table view framework (such as the free Sensible TableView) to manage all your detail view controllers instead of you having to create them manually.

Upvotes: 1

Ahmed Mohammed
Ahmed Mohammed

Reputation: 1154

You are correct. That is how you use navigation controllers. They manage other view controllers. (http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html#//apple_ref/doc/uid/TP40011313-CH2-SW27)

Upvotes: 1

Wain
Wain

Reputation: 119021

Yes it's correct. The navigation controller is a container whose purpose is to manage a stack of view controllers so it's very different to the table view controller. Try the master detail template and compare the differences.

Upvotes: 1

Related Questions