iOS4如何重启视图控制器
我想重新启动视图控制器。
我所做的是将当前视图控制器从导航堆栈中弹出,并将视图控制器的新实例推入堆栈。 然而,这是行不通的。当前视图控制器从导航堆栈中弹出,但新实例不会推送到堆栈中。
这是我的代码片段:
[[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...");
知道可能出了什么问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您的代码,您似乎正在尝试弹出当前视图控制器,然后立即重新推送它,并在两个方向上都有动画。我无法想象你为什么要这样做,但暂时把它放在一边,以下是让它发挥作用的方法。
首先,将
添加到您的 @interface 声明中。然后: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:我想你需要在通话之间留出一些时间间隔。由于您正在使用动画执行此操作,因此需要一些时间才能完成第一个调用本身。
所以首先尝试,
[[self navigationController] popViewControllerAnimated:NO];
。I guess u need to give some time interval between the calls. Since u are doing this with animation, it would require some time to finish the first call itself.
So first try,
[[self navigationController] popViewControllerAnimated:NO];
.如果您询问
VideoPlayerViewController
,请转到上一个视图控制器。因此当前视图控制器中的代码可能不会被执行。
VideoPlayerViewController
的新实例应在之前的视图控制器中实例化。If you are asking about the
VideoPlayerViewController
,goes to the previous view controller. So code in the current view controller may not be executed. The new instance of
VideoPlayerViewController
should be instantiated in the previous view controller.视图控制器是否被“弹出”在堆栈顶部?如果是这样,我可能会建议更改设计 - 我会使用 UINavigationController 的这种方法:
交换视图控制器,如果您仍然需要,还可以使用动画。
Is, or was, the view controller being "popped" at the top of the stack? If so I might suggest a change of design - I'd use this method of
UINavigationController
:to swap you're view controllers around, and with animation if you still require.