1

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..

1
  • I have the same problem. Can we do this from Interface Builder? Commented Jun 13, 2011 at 3:09

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

11 Comments

thanks for ur reply can.... i tried this but this is not working.. is there any other way....?
@praseed. Thats only display the button.you can write any action in "-(void) DoneButton{};
ya... but the button itself is not getting displayed... !
@praseed, Which Application have u used like window or view based application or navigation?
Pugal... i am new to iPhone apps development... so i cant make out wat the exact problem....in my app i have added two subclasses of table view controller in to the viewControllers array of a tabBarcontroller and this tabBarController is added to the viewControllers array of a navigation controller. one of the subclasses of tableView controller is a grouped table with cells having embedded with textfields .. when tapped on one of this textfields i am displaing a datepicker ... i want to add a done button so that i can close the date picker.. but when i tried the above method its not working..
|
1

Try with this

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

1 Comment

espuz... i tried this... but.. not working... thanx for ur reply... any other solution?
0

use this one:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.