views:

491

answers:

2

Is it possible?

I have a UINavigationBar that I'd like to have an 'edit' button next to the 'back' button. From what I've read you can only have one or the other, which makes no sense as they are separate properties of the navigationItem object(backBarButtonItem and leftBarButtonItem).

I'm assuming you have to somehow insert a custom UIView into the UINavigationBar. I'm looking into this option and if no better solution is given then I'll outline this method.

+1  A: 

Using a custom view is indeed your only option here. The UINavigationBar is not terribly flexible. What you will need to do is create a UIView that contains UIButtons. Be sure you realize that if you use a custom view, you gain none of the automatic behaviors of the backBarButtonItem; you have to create your own IBActions, and the graphics for the buttons as well.

On a related note, I'm not sure this is the best idea. It's usually wise to stick to Apple's UI guidelines; is there no where else you can put the edit button? The right side of the bar, for example?

mythogen
The question is for 2 buttons, edit and import. They both affect the current item selected. I'll have to consider other options for import.
Brenden
+2  A: 

The short answer is:

Yes, you have to add your own UIButton views (or other UIControl subclasses) to the navigation controller, yourself. So, ignore the custom *ButtonItem properties and roll it yourself.

A little more involved answer is:

Apple makes it very easy to follow their HIG guidelines, but you're on your own if you want to break them or customize. In this case, only one button is allowed, because the actual hit region is bigger than the size of the displayed button--much easier to hit from a usability standpoint.

Extraneous:

btw, there is a subtle distinction between left/rightBarButtonItem and backBarButtonItem. left/right is specified on the current UIViewController. However back is specified by the previous UIViewController.

Kelvin
If I understand right, the hit box being larger than the button makes sense, but what about segmented buttons and the like? Apple clearly allows that in their UIG.
Brenden
From my memories, if you manually attach your own segmented button (say, in the center of the nav panel) it'll work as normal.However, I suspect that when you use the nav panel's properties to attach buttons, Apple makes the hitTest:withEvent: call respond to an area larger than the actual button's view.
Kelvin