我希望重新启动 View Controller 。
我所做的是将当前 View Controller 从导航堆栈中弹出,并将 View Controller 的新实例推送到堆栈上。
但是,这不起作用。当前 View Controller 从导航堆栈中弹出,但新实例并未插入堆栈。
这是我的代码片段:
[[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...");
知道可能出了什么问题吗?
Best Answer-推荐答案 strong>
根据您的代码,您似乎正在尝试弹出当前 View Controller ,然后立即重新推送它,并在两个方向上显示动画。我无法想象你为什么要这样做,但暂时把它放在一边,这就是你如何让它发挥作用的方法。
首先,将 添加到您的 @interface 声明中。那么:
- (void)repushViewController {
self.navigationController.delegate = self;
[[self navigationController] popViewControllerAnimated:YES];
}
- (void)navigationControllerUINavigationController *)navController didShowViewControllerUIViewController *)viewController animatedBOOL)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/
|