views:

704

answers:

1

Hello All,

I have been in the process of learning to build iPhone applications for the last two weeks. I've gotten through a fair amount of content, and now I'm trying to create a modal pop up with presentModalView.

I can can successfully create and slide up a view, but I notice that modal views don't provide you with a default navigation bar at the top of the window, which makes sense for flexibility I guess. Most modal views I've seen have a "Cancel" and a "Done" or "Save" button as navigationItems on what looks to be a UINavigationController. My thought then was just to instantiate a navigation controller and push the single view onto the view controller stack, and presentModalView:navController.view ...

Because the view is relatively complex, I was trying to lay out both the UINavigationController, with the bar buttons, and the view I was hoping to push onto the stack in a single xib -- no matter what I try, I can't seem to get the linkages correct. Can you even do this? Or should I create a separate class/xib for the view I'm going to be pushing onto the navigation controller? Seems like a lot of classes and files for one screen, so my feeling is I must be missing something.

At this point, I could have done it programmatically about an hour and a half ago... however, this is a real nag, since IB seems GREAT for some things. Anyone have an experience with a situation like this?

Thanks, Josh

+1  A: 

If you're not going to use this new XIB for navigation, there's no point in making a navigation controller.

In interface builder, simply drag a UINavigationBar to the top of your view, and add a "Done" Button. Now, add an IBAction to the done button to dismiss the view controller. Your ViewController code for the dismiss IBAction should look something like this:

-(IBAction)dismiss {
    //Any logic before dismissing the modal view
    [super dismissModalViewControllerAnimated:YES];
}
Reed Olsen
Ah - duh! Thanks. I guess since I started with the navigation controller concept stuck in my head, it made more sense. Only thing I'm going to do is try and adhere to the pattern that the view controller that presented the modal view should dismiss it. So instead of using a direct IBAction, I'm going to implement a protocol and use a delegate (the parent) to call dismiss. Not sure why, but Apple says that is best practice...
Josh