Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing a navigation controller is not supported- performing segues

I created a new navigation controller in my storyboard (not programmatically!) and set it to be "Root View Controller" to a regular UIViewController and added a button in it which says- forward to the next view controller (this second view controller is a view controller which I want that will have a back button to link to the initial view controller). Now, whenever I try to link the button to the next view controller- "Pushing a navigation controller is not supported".

Help me please, and thanks

EDIT: I accidentally subclassed UINavigationController, and not UIViewController in my class. Thank you anyway.

like image 503
Lior Pollak Avatar asked May 30 '12 13:05

Lior Pollak


People also ask

How do I push navigation controller?

To push UINavigationController , first create a subclass of UIViewController , which will be a wrapper-/container- class for your UINavigationController and its content. This is a much more comprehensive answer which addresses the need to support hierarchical navigation controllers without modal presentation.

Is pushing the same view controller instance more than once?

the error is Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported. Answer: A: Answer: A: You have already pushed one of those three viewControllers somewhere else in your code previous to these lines.


2 Answers

I've tried this and have no problems, its all done in IB with no additional code required ...

  1. Start a new project, "Single View Application" using story boards
  2. Select storyboard and delete the views its produced.
  3. Drag on a new Navigation Controller (it will bring a table view with it)
  4. Delete the table and the table view controller, so you are just left with the Navigation Controller
  5. Drag on a normal view controller
  6. Right Click and drag from the Navigation controller to the new View and choose "Relationship - Root View Controller"
  7. Drag a "Bar Button Item" on to the Navbar which should be visible on the top of your ViewController, you can rename this Forward if you wish.
  8. Now drag on another view controller which is the one your "Forward" button will push in to view.
  9. Right Click and drag from the bar button to the 2nd View Controller, and choose "Push"

Run the project and you will get a Single view with a Navbar and your button, clicking your button will Push the other view and give you a Back Button to return to the first View Controller. I'll try and post a picture of my storyboard if it helps.

PushViewControllers

Plasma

like image 176
Plasma Avatar answered Sep 20 '22 03:09

Plasma


I had the same trouble. I wanted to have a navigation controller on each storyboard, so that each could run independently, be individually debugged, and so that the look would be right with the navigation bar.

Using other approaches, I found the UINavigationController would be retained from the original storyboard -- which I didn't want -- or I'd get errors.

Using the AppDelegate in your view controller to set the rootViewController worked for me (borrowing segue naming conventions from Segue to another storyboard?):

- (void)showStartupNavigationController {
NSLog(@"-- Loading storyboard --");

//Get the storyboard from the main bundle.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Startup" bundle:nil];
//The navigation controller, not the view controller, is marked as the initial scene.
UINavigationController *theInitialViewController = [storyBoard instantiateInitialViewController];

NSLog(@"-- Loading storyboard -- Nav controller: %@", theInitialViewController);

//Remove the current navigation controller.
[self.navigationController.view removeFromSuperview];
UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
window.rootViewController = theInitialViewController;
like image 36
LordParsley Avatar answered Sep 21 '22 03:09

LordParsley