17

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…

3
  • 1
    Please comment or update your previous question instead of simply posting another. Commented Aug 13, 2010 at 17:20
  • 7
    also, nobody wants to download a potentially malicious zip. use gist.github.com or friendpaste or something to display the pertinent code Commented Aug 13, 2010 at 17:29
  • 1
    possible duplicate of Navigation View in Modal View Commented Aug 13, 2010 at 18:57

3 Answers 3

48

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 *modalController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil]; modalController.delegate = self; // Set any delegate you may have // This is where you wrap the view up nicely in a navigation controller UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:modalController]; // 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 [self presentModalViewController:navigationController animated:YES completion:nil]; 
Sign up to request clarification or add additional context in comments.

7 Comments

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.
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.
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")
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
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: stackoverflow.com/questions/3477809/… and here: stackoverflow.com/questions/3476920/…
|
6

For those wanting to do this in Swift 3.x:

// Obtain your viewcontroller let viewController = ... // Initialize a navigation controller, with your view controller as its root let navigationController = UINavigationController(rootViewController: viewController) navigationController.navigationBar.barStyle = .blackTranslucent // Present it modally from the current controller present(navigationController, animated: true, completion: nil) 

Comments

5
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]; 

1 Comment

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:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.