iPhone - 快速导航栏问题

发布于 2024-11-06 15:18:10 字数 903 浏览 0 评论 0原文

我的一些视图中有一个 UINavigation 栏,但没有使用 UINavigationController。所以我不使用导航控制器来推送新视图,我再次加载新视图,其顶部有一个“静态”UINavigationBar。

因此,目前导航栏仅显示用户正在查看的视图的标题,没有其他功能。

在我的一些视图中,我要求有一个后退按钮,大约 10 个视图中有 3 个。

所以我想知道是否可以插入一个后退按钮,用于声明后退并返回到上一个屏幕,仅用于这些3 个视图,所以我必须能够插入后退按钮并检测它何时被按下。

我可以使用当前的设置执行此操作,还是需要返回并使用 UINavigationController 创建一个视图,并使用它来推送和弹出我的视图,并以某种方式抑制我不希望其显示的 7 个屏幕上的后退按钮?

编辑:

我尝试了以下方法:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBackButtonItemStyleBorder target:nil action:selector(myaction)];
[navItem setBackBarButtonItem:backButton]; //Doesn't work
[navItem setLeftBarButtonItem:backButton]; //Works but lacks the back arrow style of the back button
[backButton release];

所以我可以添加一个按钮,但它看起来不像后退按钮,有没有办法让它看起来像后退按钮,或者我应该刮擦并只使用 UINavigationController?如果我这样做,当我不需要后退按钮时,如何抑制后退按钮?

I have a UINavigation bar in a few of my views without using a UINavigationController. So i dont use the navigation controller to push new views, I load new views again which have a "static" UINavigationBar at the top.

So currently the navigation bars just show the title of which ever view the user is looking at, they have no other function.

In some of my views I have a requirement to have a back button, about 3 views out of 10.

So I was wondering if it is possible for me to insert a back button that states back and goes back to the previous screen for just these 3 views, so I would have to be able to insert the back button and also detect when it was pressed.

Can I do this with my current set up or do I need to go back and create a view with a UINavigationController and use that to push and pop my views and somehow suppress the back button on the 7 screens that I dont want it to display on?

EDIT:

I've tried the following way:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBackButtonItemStyleBorder target:nil action:selector(myaction)];
[navItem setBackBarButtonItem:backButton]; //Doesn't work
[navItem setLeftBarButtonItem:backButton]; //Works but lacks the back arrow style of the back button
[backButton release];

So I can add a button but it doesn't look like the back button, is there a way to make it look like the back button or should I scratch and just use a UINavigationController? And if I do how can I suppress the back button when I dont want one?

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

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

发布评论

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

评论(1

时间海 2024-11-13 15:18:10

如果我理解正确的话,你可以。只需将自定义按钮添加到导航中作为 leftBarButtonItembackBarButtonItem 并为其指定自定义按钮按下操作即可。在按钮方法中,您可以删除此视图并显示以前的视图。但这就是说,如果您的应用程序在所有屏幕上都有导航栏,则更好的方法是使用普通的 UINavigationController 。

You can if i get you correctly. Just add a custom button to the navigation as leftBarButtonItem or backBarButtonItem and give it a custom button press action. in the button method you can remove this view and show your previous view. But that said the better way is to use normal UINavigationController if your app has Navigation bar in all screens.

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