user347161
user347161

Reputation: 327

adding button to the navigation bar

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

Answers (3)

SamSol
SamSol

Reputation: 2881

use this one:

UIButton *myBtn = [[UIButton alloc]init];
[self.navigationItem.titleView addSubview:myBtn];

Upvotes: 0

Pugalmuni
Pugalmuni

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

emenegro
emenegro

Reputation: 6971

Try with this

UIBarButtonItem* _doneButton;
self.navigationItem.rightBarButtonItem = _doneButton;

Upvotes: 1

Related Questions