如何手动设置“返回"?iOS 应用程序中的目的地

编程入门 行业动态 更新时间:2024-10-27 07:19:19
本文介绍了如何手动设置“返回"?iOS 应用程序中的目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个名为detailViewController"的 UIViewController.

I have a UIViewController called 'detailViewController'.

这个视图控制器是通过多个不同的 segue 使用 push segue 访问的.

This view controller is accessed through multiple different segues using the push segue.

我面临的问题是 detailViewController 上的后退按钮将用户带回前一个视图控制器(应该如此),但是我希望后退按钮将用户带到 masterViewController(默认的 UIViewController应用程序).

The problem I am facing is that the back button on the detailViewController takes the user back to the previous view controller (as it should), however I would like the back button to take the user to the masterViewController (the default UIViewController in the app).

我该怎么做?

我曾尝试更改 segue 类型,但实际上并没有做任何事情.

I have tried changing the segue types however that didn't really do anything at all.

彼得

推荐答案

你要找的方法是 UINavigationController 的 popToRootViewControllerAnimated:

The method you're looking for is UINavigationController's popToRootViewControllerAnimated:

来自 文档:弹出堆栈上除根视图控制器之外的所有视图控制器并更新显示."

From the documentation: "Pops all the view controllers on the stack except the root view controller and updates the display."

您需要创建一个自定义后退按钮.你不能 afaik 覆盖后退按钮的功能.

You'll need to create a custom back button. You can't afaik override the back button's functionality.

比如:

UIButton *myBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myBackButton addTarget:self action:@selector(popToRoot:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myCustomBackButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myBackButton];
[self.navigationItem setLeftBarButtonItem:myCustomBackButtonItem];

然后 popToRoot: 的实现看起来像:

and then the implementation of popToRoot: would look like:

- (void)popToRoot:(id)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

这篇关于如何手动设置“返回"?iOS 应用程序中的目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 02:29:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183578.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   目的地   quot   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!