如何在UINavigationController中添加Button

时间:2011-01-03 06:55:35

标签: objective-c cocoa-touch 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添加一个按钮并得到以下异常请帮助我

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

1 个答案:

答案 0 :(得分:2)

您无法直接在导航栏上设置项目,您需要浏览导航项目,您可以从导航控制器中显示的视图控制器中获取该项目。所以,     contacts.navigationItem.leftBarButtonItem = yourItem;