Switching between sister views via UINavigationViewController

I am using NavigationViewController to navigate between main view and detail views. Now I want to be able to go to the detailed view of the sister without previewing the main view, and I tried to do popViewController and pushViewController in the same method or popViewController in the detail view and then pushViewController in mater viewDidLoad after popViewController, but it won't work - view it just ends up going back to the main view without switching to details. Any idea what to do?

The solution suggested here doesn't work as far as I can tell: Problem with displaying content views

+3


source to share


1 answer


I've never tried it, but this should work:

// create instance of new view controller
MyViewController *myViewController = [[MyViewController alloc] init];

// get current stack of viewControllers from navigation controller
NSMutableArray *viewControllers = [[self.navigationController viewControllers] mutableCopy];

// replace top view controller in stack
[viewControllers replaceObjectAtIndex:([viewControllers count] - 1) withObject:myViewController];

// set modified stack of view controllers in navigation controller
[self.navigationController setViewControllers:viewControllers animated:YES];

      



As per the docs, your app will navigate to the new view controller using a push animation, and then when the back button is clicked, it will be as if the view controller you exited from was never there. (If you don't want animation use animated:NO

)

+4


source







All Articles