如何在UINavigationController中添加按钮 [英] How to add Button in UINavigationController

查看:45
本文介绍了如何在UINavigationController中添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

navigator=[[UINavigationController alloc]initWithRootViewController:contacts];

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]
       initWithTitle:@"Delete"
       style:UIBarButtonItemStyleBordered
       target:self
       action:@selector(makeCall)];

//[[self.navigator navigationItem] setLeftBarButtonItem:nextButton];
self.navigator.navigationBar.items=[NSArray arrayWithObject:nextButton];

我正在向UINavigationController添加一个按钮,并遇到以下异常,请帮我

I am adding a button to UINavigationController and got following exception please help me

2011-01-03 11:46:26.626 Appointment[2243:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot call setItems:animated: directly on a UINavigationBar managed by a controller.'
2011-01-03 11:46:26.634 Appointment[2243:207] Stack: (
3040


推荐答案

您不能直接在导航栏上设置项目,需要仔细阅读
contacts.navigationItem.leftBarButtonItem = yourItem;

You can't set the items on a navigation bar directly, you need to go through the navigation item, which you get from the view controller your displaying in the navigation controller. So, contacts.navigationItem.leftBarButtonItem = yourItem;

这篇关于如何在UINavigationController中添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆