我希望重新启动视图控制器。
我要做的是将当前视图控制器从导航堆栈中弹出,并将视图控制器的新实例推入堆栈。
但是,这不起作用。当前视图控制器从导航堆栈中弹出,但是新实例未推送到堆栈中。
这是我的代码段:
[[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...");
知道有什么问题吗?
最佳答案
根据您的代码,您似乎正在尝试弹出当前的视图控制器,然后立即重新按两个方向的动画对其进行推送。我无法想象您为什么要这样做,但是暂时将其搁置一旁,这就是使它起作用的方法。
首先,将<UINavigationControllerDelegate>
添加到您的@interface声明中。然后:
- (void)repushViewController {
self.navigationController.delegate = self;
[[self navigationController] popViewControllerAnimated:YES];
}
- (void)navigationController:(UINavigationController *)navController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
navController.delegate = nil;
VideoPlayerViewController *videoPlayer = [[VideoPlayerViewController alloc] init];
[videoPlayer setMedia:media];
[navController pushViewController:videoPlayer animated:YES];
[videoPlayer release];
}
关于iphone - iOS4如何重启 View Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6705204/