Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push view controller into modal view controller view

I'm trying to get working a simple operation. At least it seems simple. Ok, what I'd like to do is to push a view (with push view controller) from a view that has been pushed with modal view controller.

View1 --(push using modal view controller)-->View2--(push using push view controller)--View3.

Rigth now, i'm doing tests so i'm using a button to start the action. Here's the code I use to push from View2 to view 3:

//view2.h
UIToolbar *bar;
UIBarButtonItem *button;
UIToolbar *toolbar;

}

- (IBAction)demissModal:(id)sender;
- (IBAction)goView3:(id)sender;

@end

//view2.m
- (IBAction)goView3:(id)sender{

View3 *view_3 = [[View3 alloc] initWithNibName:@"View3" bundle:nil];
[self.navigationController pushViewController:view_3 animated:YES];

}

This is the same code I use to push View1 to View2, and it works. But when pushing View2 to View3, it's not working. Any idea of why happens that? Thanks!

like image 815
joan2404 Avatar asked Oct 11 '12 22:10

joan2404


People also ask

How do I push a view controller?

Pushing a view controller causes its view to be embedded in the navigation interface. If the animated parameter is true , the view is animated into position; otherwise, the view is simply displayed in its final location.

How do I pop navigation controller in Swift?

You can do it by selecting the View Controller in Storyboard editor and clicking Editor -> Embed In -> Navigation Controller. Also make sure that you have your Storyboard Entry Point (the arrow that indicates which view controller is presented first) either pointing to Navigation Controller or before it.


1 Answers

View Controllers aren't actually 'modal' or 'push' view controllers. Modal or Push describe a transition between view controllers (called segues if you're using storyboards).

What I think you're asking is how to modally present a view controller, and then push another controller. The trick is when you modally present view controller #1, to actually present a navigation controller with its root view controller set as view controller #1.

MyViewController *myViewController = [MyViewController alloc] init];
UINavigationController *navController = [UINavigationController alloc] initWithRootViewController:myViewController];

// Presuming a view controller is asking for the modal transition in the first place.
[self presentViewController:navController animated:YES completion:nil];
// Now in myViewController, call [self.navigationController pushViewController:secondViewController animated:YES];

This is what it looks like using storyboards: enter image description here

like image 172
MaxGabriel Avatar answered Sep 28 '22 19:09

MaxGabriel