导航回主 ViewController 解雇ViewControllerAnimated 困境

发布于 2025-01-07 05:26:25 字数 646 浏览 1 评论 0原文

我有 2 个 ViewController 直接与推送序列连接。我通过调用 [self PerformSegueWithIdentifier:@"segueIdentifier" sender:sender] 从第一个视图控制器导航到第二个视图控制器。在第二个方法中,我有一个绑定到“完成”按钮的 IBAction 方法。按下该按钮基本上应该会导致显示第一个视图控制器(类似于后退按钮)。我设法做到了这一点:

NSArray *viewControllers = self.navigationController.viewControllers;
[self.navigationController popToViewController:[viewControllers
objectAtIndex:0] animated:YES];

我确实尝试通过使用来达到相同的效果:

[self dismissViewControllerAnimated:YES completion:nil];

不管我尝试了什么,尽管这没有完成工作。我试图了解我到底错过了什么,但我无法弄清楚。 missViewControllerAnimated 方法是否仅适用于 Modal segues(这是唯一想到的)。

谢谢

I have 2 ViewControllers directly connected with a push segue. I am navigating from first to second view controller by calling [self performSegueWithIdentifier:@"segueIdentifier" sender:sender]. On the second one I have an IBAction method that is bound to a "Done" button. Pressing that button should basically cause the first view controller to be displayed (sort of a back button). I managed to do that with:

NSArray *viewControllers = self.navigationController.viewControllers;
[self.navigationController popToViewController:[viewControllers
objectAtIndex:0] animated:YES];

I did try to achieve the same effect by using:

[self dismissViewControllerAnimated:YES completion:nil];

No matter what I tried though this didn't do the job. I am trying to understand what exactly am I missing but I can't figure it out. Does dismissViewControllerAnimated method work only with Modal segues ( this is the only thing that came to mind ).

Thank you

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

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

发布评论

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

评论(1

紅太極 2025-01-14 05:26:25

是的,

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

就是当 UIViewController 以模态方式显示时。

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

应该做你正在寻求的事情。

所以基本上,在你的第二个 VC 中:

[self.navigationController popViewControllerAnimated:YES];

如果你阅读 UIViewController 和 UINavigationController 参考资料,你会省去很多麻烦。两次;)

Yes,

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

is when a UIViewController is displayed modally.

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

should do what you are seeking.

So basically, in your second VC:

[self.navigationController popViewControllerAnimated:YES];

You will save you a lot of trouble if you read the UIViewController and UINavigationController references. Twice ;)

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