问题描述
限时送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:关键词]
发布评论