In my application I have tabbarcontroller
that is not the first viewcontroller
. It will open form a navigationcontroller
.(by pushing it to stack from its parent)
Now I want to add a rightbarbuttonitem to the navigationbar of this view. I am using this code:
UIBarButtonItem *b= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionBarButtonPressed)];
self.navigationController.navigationItem.rightBarButtonItem= b;
but it is not working-any buttons do not appear in the navigation bar. I searched about this but in all topic this codes has been answered as working solution. Maybe it should be different when using tabbar
and navigationbar
together. Does any one know any other working solutions.
Edit I add a break point ad last line and checked some variables. This is the result:
(lldb) po self.navigationController.navigationItem.rightBarButtonItem
error: property 'navigationItem' not found on object of type 'id'
error: 1 errors parsing expression
(lldb) po self.navigationController;
nil
(lldb) po self.navigationItem;
<UINavigationItem: 0x8997070>
(lldb)
(lldb) po self.navigationController.navigationItem.rightBarButtonItem
error: property 'navigationItem' not found on object of type 'id'
error: 1 errors parsing expression
It seems that navigationController
is nil
and we directly should call navigationItem
. So I changed the code but again not working. So I checked these variables:
(lldb) po self.navigationItem
<UINavigationItem: 0x8d789c0>
(lldb) po self.navigationItem.rightBarButtonItem
error: property 'rightBarButtonItem' not found on object of type 'id'
error: 1 errors parsing expression
(lldb)
it seems that rightbarbuttonitem
is not exist. So what should we do now?