向导航栏添加后退按钮
我已向 UIViewController 添加了一个导航栏。它仅从另一个 UIViewController 显示。我想要一个形状类似于箭头的左侧后退按钮,就像普通的导航栏后退按钮一样。看来只能通过IB添加一个bar按钮了。我猜后退按钮需要以编程方式添加。关于我应该如何执行此操作有什么建议吗?
目前,在 RootController 中,我通过简单地执行 addSubView 来推送另一个 UIViewController (viewB)。在viewB中,我想显示导航栏。该应用程序是基于视图的,而不是基于导航控制器的。
I've added a navigation bar to a UIViewController. It is displayed from another UIViewController only. I'd like to have a left side back button that is shaped similar to an arrow, just like the normal navigation bar back button. It seems I can only add a bar button through IB. I'm guessing the back button needs to be added programmatically. Any suggestions on how I should do this?
Currently, in the RootController, I push another UIViewController (viewB) by simply doing an addSubView. In viewB, I want to display the navigation bar. The app is view based, not navigation controller based.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是导航控制器:
如果您没有使用导航控制器,请查看 Three20 样式 用于制作自定义栏按钮的组件。
If you're using a navigation controller:
If you're not using a navigation controller, look into the Three20 style components to make custom bar buttons.
我已经按照以下方式完成了
在 viewDidLoad 方法中我有以下代码:
然后在标头中添加对 UINavigationBarDelegate 协议的一致性并以这种方式实现委托方法:
I have done it the following way
In viewDidLoad Method I have this code:
Then add conformity to UINavigationBarDelegate protocol in the header and implement the delegate method this way:
解决此问题的另一种方法是设置导航栏的 items 属性,而不是将栏项目连续推入导航栏堆栈:
Another approach to solve this problem is to set the items property for the navigation bar instead of consecutively pushing the bar items into nav bar stack: