This might look like a silly question to some, but handling the different types of controllers in an iPhone application is still a little fuzzy to me. Here’s the setup:
I have a Tab Bar application with four tabs. Each tab passes control to its respective ViewController, where some of those are initialized with a .XIB file and some are done purely programmatically. One of the programmatic ones is DirectionsViewController, which is essentially a UITableViewController. Selecting a cell from its table needs to present (modally) a DetailedDirectionsViewController, which needs to have some sort of back-reference to the presenting view controller. I figured the easiest way to do this is to add a navigation controller to the Directions and DetailedDirections VCs – except I don’t know how to do this without a .XIB file.
Also, the way I hand control over to DetailedDirections is by changing Directions the following way:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.tabBarController presentModalViewController:vc animated:YES];
}
I seem to recall one of my professors saying that presentModalViewController is kind of an old method and there are better alternatives… I just can’t remember them right now.
For what you want to do it would be best to have the tab in your tabbar manage a UINavigationController, and to set the
rootViewControllerof that navigation controller to your DirectionsViewController.Then in your direction view controller’s
didSelectRowAtIndexPath:methods you can do the following:And it will function like you want it to. The UINavigation controller will take care of putting a back button on your detailed directions view controller.