在dismissModalViewControllerAnimated后调用popToRootViewControllerAnimated

发布于 2024-09-26 03:00:16 字数 482 浏览 4 评论 0原文

我正在工作的应用程序,其中我调用 presentModalViewController ,一旦完成(调用 dismissModalViewControllerAnimated:YES),它应该立即调用 popToRootViewControllerAnimated

但问题是 dismissModalViewControllerAnimated:YES 工作正常,但 popToRootViewControllerAnimated 在它之后不起作用。

代码如下所示:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self.navigationController popToRootViewControllerAnimated:YES];

I am working application in which i calling presentModalViewController and once finished(calling dismissModalViewControllerAnimated:YES) it should immediately call popToRootViewControllerAnimated.

But the issue is dismissModalViewControllerAnimated:YES is working properly but popToRootViewControllerAnimatedis not working after it.

The code is shown below:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self.navigationController popToRootViewControllerAnimated:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

灼痛 2024-10-03 03:00:16

尝试这样的事情:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3];


-(void)patchSelector{
  [self.navigationController popToRootViewControllerAnimated:YES]; 
}

它不是那么整洁,但应该可以工作。

更新:
您应该使用

 [self dismissModalViewControllerAnimated:YES];

呈现

 [self.navigationController dismissModalViewControllerAnimated:YES] ;

模式的对象是视图控制器,而不是导航控制器。

Try something like this:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3];


-(void)patchSelector{
  [self.navigationController popToRootViewControllerAnimated:YES]; 
}

It is not so neat but it should work.

UPDATE:
You should use

 [self dismissModalViewControllerAnimated:YES];

instead

 [self.navigationController dismissModalViewControllerAnimated:YES] ;

The object that is presenting the modal is the view controller, not the navigation controller.

憧憬巴黎街头的黎明 2024-10-03 03:00:16

如果您有一个带有一堆 UIViewController 的导航控制器:

[self dismissModalViewControllerAnimated:YES];
[(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES];
//UIViewController *vc = [[UIViewController new] autorelease];
//[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES];

假设,其中调用模态视图控制器的视图控制器具有 navigationController。

If you have a navigation controller with a stack of UIViewControllers:

[self dismissModalViewControllerAnimated:YES];
[(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES];
//UIViewController *vc = [[UIViewController new] autorelease];
//[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES];

Assumes, that view controller in which called modal view controller has navigationController.

独﹏钓一江月 2024-10-03 03:00:16

我遇到了类似的事情。您需要首先复制 self.navigationcontroller 并保留自己,因此当您调用第二个 pop 时,仍然存在对 NC 的引用,并且您仍然存在。

    // locally store the navigation controller since
    // self.navigationController will be nil once we are popped
UINavigationController *navController = self.navigationController;

    // retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];

    // Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:someViewController animated:NO];

请参阅:如何在一次操作中从 UINavigationController 中弹出一个视图并将其替换为另一个视图?

I ran into something similar to this. You need to make a copy of your self.navigationcontroller first and also retain yourself, so when you call the second pop, there is still a reference to the NC and you still exist.

    // locally store the navigation controller since
    // self.navigationController will be nil once we are popped
UINavigationController *navController = self.navigationController;

    // retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];

    // Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:someViewController animated:NO];

see : How can I pop a view from a UINavigationController and replace it with another in one operation?

梦行七里 2024-10-03 03:00:16

我想,您没有

[self.navigationController popToRootViewControllerAnimated:YES];

在目标模式视图控制器中调用。检查一下。

I guess, you are not calling the

[self.navigationController popToRootViewControllerAnimated:YES];

in the target modal viewcontroller. check that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文