-1

I am trying to replicate iPhone's Contacts application and to create a button over navigation bar. Actually the view is not a UINavigation controller. I just added the navigation bar programatically but I am struggling to create a title and a button on that navigation bar.

I am using the following code

[[UIBarButton alloc]] initWithTitle:@"Done" 
                              Style:UIBarButonItemStyleBorderd 
                              target:Self 
                              action:selector(btnClicked)];  
self.navigationItem.rightBArButtonItem=btnDone; 
[self.view addSubview:navigationBar]; 

Please refer iphone contact application in simulator.

Any help will be appreciated.

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
naveen
  • 19
  • 1
  • 6
  • 2
    On StackOverflow, it is recommended that you put a bit of code and explain more in details what you have tried so far. – BlueTrin Aug 31 '12 at 09:43
  • sorry i dont have net access in my mac system so it is not possible to put code.. – naveen Aug 31 '12 at 09:49
  • what is the problem u r facing? do u wanna add BarButtonitem? – iMeMyself Aug 31 '12 at 09:51
  • i tried allocating [[UIBarButton alloc]] initWithTitle:@"Done" Style:UIBarButonItemStyleBorderd target:Self action:selector(btnClicked)}; – naveen Aug 31 '12 at 09:52
  • add what you have tried(code and error log) to ur Question to get better answers.. – iMeMyself Aug 31 '12 at 09:58
  • @ iShru the button is not visible. i tried the code you gave .is there any other option ? – naveen Aug 31 '12 at 10:00
  • @iShru ya i want to add barButton to navigation Bar. it is not a UINavigation Controller it is ordinary UIController i added that navigation bar programatically. – naveen Aug 31 '12 at 10:02
  • [[UIBarButton alloc]] initWithTitle:@"Done" Style:UIBarButonItemStyleBorderd target:Self action:selector(btnClicked)]; self.navigationItem.rightBArButtonItem=btnDone; [self.view addSubview:navigationBar]; – naveen Aug 31 '12 at 10:04

1 Answers1

0

try this code chunk

UIBarButtonItem *rightButton = **[[UIBarButtonItem alloc] initWithTitle:@"Done" 
    style:UIBarButtonSystemItemDone target:nil action:nil];**
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];
item.rightBarButtonItem = rightButton;
item.hidesBackButton = YES;
[bar pushNavigationItem:item animated:NO];
[rightButton release];
[item release];

and go through other SO links like this

Community
  • 1
  • 1
iMeMyself
  • 1,649
  • 13
  • 28