tags:

views:

121

answers:

2

Hi, still cannot figure out what I am doing wrong. Just trying to get a modal view with a navigation controller inside.

Here is my project http://www.matthewpateman.com/New.zip

Can anybody tell me what I am doing wrong? I want "ShopModalView.xib" to pop up in the navigation controller, but its just diplaying a blank page…

A: 
ShopModalViewController *shopMVC = [[ShopModalViewController alloc] initWithNibName:@"ShopModalViewController" bundle:nil];
//set properties
UINavigationContrller *navCon = [[UINavigationController alloc] initWithRootViewController:shopMVC];
[self presentModalViewController:navCon animated:YES];
[shopMVC release];
[navCon release];
DVG
I used your code but it gives me this error message:2010-08-13 19:55:54.718 Nav[95599:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:
Matthew Pateman
A: 

Matt,

Update: Your project was a mess... you need to get back to the basics man. Here's a corrected version: http://www.mediafire.com/file/wddr123gwzkldty/New_IWasRobbed2.zip

// Present it as a modal view and wrap the controller in a navigation controller to provide a navigation bar in case you want to add edit, save, etc buttons
// ModalViewController is the view controller file name that gets the .h file included at the top, also make sure the XIB name is the same name
ModalViewController *addController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
addController.delegate = self;

// This is where you wrap the view up nicely in a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];

// You can even set the style of stuff before you show it
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

// And now you want to present the view in a modal fashion all nice and animated
[self presentModalViewController:navigationController animated:YES];

// make sure you release your stuff
[navigationController release];
[addController release];

In interface builder, all I have in ModalViewController.xib is a UIView with some various controls on it like UIButtons or UIImageViews etc... Make sure the "view" hook-up for the UIView with all those controls is hooked up to "File's Owner"

That's it! Nice and simple.

iWasRobbed
wow! Thanks for your help! It was very helpful. Really appreciate you spending your time fixing it up. As you said! Works great - nice and simple.
Matthew Pateman
Not a prob, but make sure you take a few lessons learned: You were missing XIB files in XCode for some of your view controllers, you were missing a MainWindow.xib which is why you were getting an `NSInternalInconsistencyException` error (it had nothing to load in `applicationDidFinishLaunching` and no way to set up the nav controller initially). You were also hiding the nav controller bar from showing when your view appeared. Keep your XIB's named the same as the view controller class that handles them... it's one less thing to remember.
iWasRobbed
You may want to create a whole new example project and set it up yourself now that you have something to work off of. XCode actually has a navigation controller template to work with if you know from the beginning you'll be using one (XCode -> New project -> iPhone OS application -> Navigation based app -> uncheck "Use core data for storage")
iWasRobbed
Also one last thing, when you know you want to add a new view controller to the application do it by right clicking the model tree area, clicking Add -> New file -> Cocoa Touch class -> UIViewController subclass and make sure the "With XIB for user interface" box is checked so it creates the XIB for you. It'll make your life easier
iWasRobbed
by the way, you should probably accept the answers on the other 2 questions you posted related to this since those people were correct. In the future, just update your *first* post and if no one answers you, you can offer a bounty of reputation points which encourages more people to answer. here: http://stackoverflow.com/questions/3477809/navigation-view-in-modal-view and here: http://stackoverflow.com/questions/3476920/uinavigationview-in-modal-view
iWasRobbed
Also, I updated the example app above so use this newer version to go off of. Best of luck
iWasRobbed