I wish to restart a view controller.
What I’ve done is to pop the current view controller off the navigation stack, and push a new instance of the view controller onto the stack.
However, this does not work. The current view controller is popped off the navigation stack but, the new instance is not pushed onto the stack.
Here is my code snippet:
[[self navigationController] popViewControllerAnimated:YES];
VideoPlayerViewController *videoPlayer = [[VideoPlayerViewController alloc] init];
[videoPlayer setMedia:media];
[[self navigationController] pushViewController:videoPlayer animated:YES];
[videoPlayer release];
videoPlayer = nil;
NSLog(@"Restarting view controller...");
Any idea what could be wrong?
Based on your code, it looks like you’re trying to pop the current view controller and then immediately re-push it, with animations in both directions. I can’t imagine why you’d want to do this, but setting that aside for the moment, here’s how you can make it work.
First, add
<UINavigationControllerDelegate>to your @interface declaration. Then: