tags:

views:

85

answers:

4

hi friends,

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  A: 

Try with this

UIBarButtonItem* _doneButton;
self.navigationItem.rightBarButtonItem = _doneButton;
Espuz
espuz... i tried this... but.. not working... thanx for ur reply... any other solution?
A: 

Hi praseed,

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.

Pugal Devan
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{};
Pugal Devan
ya... but the button itself is not getting displayed... !
@praseed, Which Application have u used like window or view based application or navigation?
Pugal Devan
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..
I have used same code and it worked well. If You are used view controller and you should add navigation controller,then only you can used the above code.
Pugal Devan
i have used a view based application....
but my root controller is a navigation controller ... am i right...?
so why should i add a navigation controller... i didnt get that .... am i going wrong in my concepts...
okay. I have one question. Have you seen navigation bar in that particular view (Which you want to display the done button).
Pugal Devan
yes/...i can see it
If you want to add navigation controller in your delegate method. But you have used table view controller means it doesnt need.
Pugal Devan
ok so wat ur suggetions so that i can modify the application... Pls can u explain it....
i have posted another answer, try that one...
Pugal Devan
A: 

Try this one,

  UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(rightbutton)];
   self.navigationItem.rightBarButtonItem = rightbutton;
   [rightbutton release];
Pugal Devan
A: 

use this one:

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