views:

240

answers:

1

I have a three view tab bar app the second view of which I want to contain a navigation controller. in the navcontroller the first/root view will be a custom uiview containing a uitableview that when you touch a cell will push another custom uiview in to disclose details about the touched cell.

I have found the documentation on doing this but it is not making sense to me or seems to be flying over my head. The docs say that you have to create the uiviewcontroller located in the navcontroller views or at least refer to them programatically. I have been using Interface builder and have become quite comfortable using it, so doing it programatically scares me a bit.

Also, This piece of code from the documentation seems troubling:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:myNavigationController.view];
 }

above taken from "ViewController Programming for iPhoneOS" apple documentation

wouldn't this load up and display the UINavigationView immediately?

one problem is I dont want to display the navView immediately. the navController/stack is a secondary tab. So how and where do I impliment my navController(right now I have it instaciated in my delegate(which I think is correct)? I've been able to load up a basic UInavigationController with a navigation bar and a blank view, --minus the custom content view, through interface builder but I'm at a loss as to how to populate the custom content views.

Hope this makes sense.

Any help would be appreciated,

Nick

+1  A: 

The first thing to understand is how UINavigationController works. It pushes UIViewControllers, not views. So, when something happens in your second tab (where the UINavigationController lives) you will push a UIViewController onto the stack.

This is typically done in:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

Which is part of the UITableViewDelegate Protocol.

So, when tableView:didSelectRowAtIndexPath is called, you need to figure out which UIViewController to push onto the stack. You can either load this View Controller from a nib, or create it programatically. Since you feel comfortable with IB, I would suggest loading it from a nib.

I would not worry about trivia like "where should I instantiate my UINavigationController?" right now. First, get it working. Then worry about where things "should" go.

It might be best to get the UINavigationController stuff working in a separate project, then fold it into your main project. This lets you ignore lots of little details while you focus on the Navigation Controller.

Rob Jones
That makes sense, I have been using didselectrowatindexpath quite a bit so I am familiar with that method, however I'm still a little confused on what I should actually be doing here,do i send the uinavcontroller a message(if so what message?)? plus I can't even get the custom uitableview to show up as the root controller in the custom content area of the uinavcontroller so ther'e no way to select a row at an index path if you get my drift. appreciate any clarification.Nick
nickthedude
i also like your idea of breaking it out into a separate app just to simplify it until it makes sense. thanks.
nickthedude
In tableView:didSelectRowAtIndexPath: you should send a pushView message to your nav controller. You need to provide the UIViewController as a parameter to pushView. This is the VC that controls the view you wish to be active. You can create it programatically or load it from a nib.
Rob Jones