iPhone - 快速导航栏问题
我的一些视图中有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你可以。只需将自定义按钮添加到导航中作为
leftBarButtonItem
或backBarButtonItem
并为其指定自定义按钮按下操作即可。在按钮方法中,您可以删除此视图并显示以前的视图。但这就是说,如果您的应用程序在所有屏幕上都有导航栏,则更好的方法是使用普通的 UINavigationController 。You can if i get you correctly. Just add a custom button to the navigation as
leftBarButtonItem
orbackBarButtonItem
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 normalUINavigationController
if your app has Navigation bar in all screens.