Reputation: 327
i have a problem while adding button to the navigation bar.. My application consist of two view controllers added to the viewControllers array of a tabBarController. Inturn this tabBarController is added to the viewControllers array of a navigationController. In one of the views i have a textfield for entering dates . On the tap of this textfield the datepicker will pop up. simultaneously i want to display a done button on the navigation bar. how can i do this... i tried using
self.tabBarController.navigationController.navigationItem.rightBarButtonItem = self.doneButton;
But this is not working...
Pls help me out..
Upvotes: 1
Views: 408
Reputation: 2881
use this one:
UIButton *myBtn = [[UIButton alloc]init];
[self.navigationItem.titleView addSubview:myBtn];
Upvotes: 0
Reputation: 9390
Try this code,
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"")
style:UIBarButtonItemStyleBordered
target:self
action:@selector(DoneButton)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
Best of luck.
Upvotes: 2
Reputation: 6971
Try with this
UIBarButtonItem* _doneButton;
self.navigationItem.rightBarButtonItem = _doneButton;
Upvotes: 1