In my StoryBoard, I have embedded my root view controller inside a Navigation Controller, and this view gets displayed when the app is launched. The user then goes through a series of views, which are basically view controllers presented modally.
I'm trying to implement a function to go back to the root view controller, so I called
-(IBAction)backToMenu{
NSLog(@"Back to menu");
[self.navigationController popToRootViewControllerAnimated:YES];
}
but nothing happens. If I do NSLog(@"%@", self.navigationController");
it prints null
, so I guess that's the source of my problem. You can't call popToRootViewControllerAnimated:
on a view controller that's been presented modally.
Unless you pass a reference to the root view controller. But is this the right approach? If so, how do you pass a reference to the root view controller? As all my view controllers are instances of a custom subclass of UIViewController
, I tried doing inserting this in said class's code :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
[[segue destinationViewController] navigationController] = [[segue sourceViewController] navigationController];
}
but I get an error saying that navigationController
is not assignable.
Any thoughts?