How to add Button in UINavigationController

戏子无情 提交于 2019-12-25 01:24:58

问题


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];

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

回答1:


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;



来源:https://stackoverflow.com/questions/4582587/how-to-add-button-in-uinavigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!