0

How to present modal ViewController on top of UINavigationController without using initWithRootViewController, just with adding it to the existing navigationcontroller stack?

my code is:

TableViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"TableView"];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:navi animated:NO completion:nil];

edit: what i actually want is to do like: "vc1 push vc2 modal vc3" and than use "poptoroot...to vc1". But the initWithRootViewController (vc3) is ruining it.

3
  • present modal and adding to an existing navigationController are mutual exclusive. Maybe you are looking for [self.navigationController pushViewController: controller animated:YES];?! Commented Feb 11, 2014 at 7:22
  • 1
    i dont want to use push. the code works perfectly at is. what i actually want is to do like: "vc1 push vc2 modal vc3" and than use "poptoroot...to vc1". But the initWithRootViewController (vc3) is ruining it. Commented Feb 11, 2014 at 7:31
  • try presenting your controller instead of navi Commented Feb 11, 2014 at 8:14

1 Answer 1

1

If you want to change the stack of navigationController. Use :

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.

It will help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.