views:

850

answers:

4

Does anyone know how to add two system buttons to the top right side of my navigation toolbar. I know that custom buttons can be added, and i really dont understand why the system buttons can't do this to.

And i really need it, i need a add button and an edit button.

edit to reorder and delete table rows. add to add a new row.

I cant use the bottom toolbar because i have a tabbar their.

Could somebody help me out?

A: 

With the default navigation bar, you can only have three buttons, unless I'm missing something. One on the left, one in the center, and one on the right. Even if you create a smaller button and think you have enough space, the touches will all register to the same button (whichever is linked to the right or left). If you want to get functionality like google's navbars, I would suggest implementing it yourself. It really wouldn't be that difficult, and you would get exactly the functionality that you want. If you decide to do this, I'm sure SO can guide you through difficult parts.

TahoeWolverine
A: 

Oke thanks for your information, i am using my own two custom button with a png image of the default system buttons.

Ton
A: 

I wonder what would happen if you'd use a custom view for your UINavigationItem:

myViewController.navigationItem.titleView = myCustomView;

I imagine the titleView might expand all the way to the right if you don't have a button there. I'noticed that title text gets more space if there is no right button.

Then you could add a label (for the title) and your two buttons to that custom view.

Thomas Müller
+3  A: 

Something like this should work (substitute your own images and action methods):

#define ACTIONEDIT  0
#define ACTIONADD   1
...
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] 
       initWithItems: [NSArray arrayWithObjects: 
         [UIImage imageNamed:@"icon-edit.png"], 
         [UIImage imageNamed:@"icon-add.png"],
         nil]
       ];
[segmentedControl addTarget:self 
                     action:@selector(segmentAction:) 
           forControlEvents:UIControlEventValueChanged];

segmentedControl.frame = CGRectMake(0, 0, 90, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
[segmentedControl setEnabled:YES forSegmentAtIndex:ACTIONEDIT];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
                       initWithCustomView:segmentedControl];

...

- (void)segmentAction:(id)sender
{
  UISegmentedControl* segCtl = sender;
  int action = [segCtl selectedSegmentIndex];
  switch (action) {
    case ACTIONADD:
     [self addToList];
     break;
    case ACTIONEDIT:
     [self editList];
     break;
  }
}
Ramin