如何在iPhone中的uinavigationbar上添加栏按钮
我的类是一个普通的视图控制器,我通过 IB 添加了一个导航栏,并且我使用以下代码以编程方式在导航栏左侧添加了一个栏按钮项,
UIBarButtonItem *addButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(tourBtnClicked:)];
self.navigationItem.leftBarButtonItem = addButton1;
但它不起作用...我应该也以编程方式添加导航栏还是应该我的类 uinavigationcontroller
谢谢
My class is a normal view controller and I added a navigation bar through IB and i am adding a barbutton item on left to the navigation bar programmatically using the following code
UIBarButtonItem *addButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(tourBtnClicked:)];
self.navigationItem.leftBarButtonItem = addButton1;
but its not working... should i add the navigationbar also programmatically or should my class a uinavigationcontroller
Thank u
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不使用
UINavigationController
,则需要添加代码以通过编程方式管理导航栏。例如,您需要使用以下方法向导航栏发送一条消息,以将导航项推送到其堆栈上:您还应该确保
navigationItem
属性当前不是nil
当您尝试设置其属性时。来自navigationItem
属性的UIViewController
类引用:If you're not using a
UINavigationController
, you will need to add code to manage the navigation bar programmatically. For example, you'd need to send a message to the navigation bar to push a navigation item onto its stack using the following method:You should also make sure the the
navigationItem
property isn't currentlynil
when you attempt to set its properties. From theUIViewController
class reference for thenavigationItem
property: