PDA

View Full Version : UIBarButtonItem not derived from UIView???




lawicko
Aug 28, 2008, 08:38 AM
Ok, so here is what I want to do - I want to customize my navigation bar so that I have more than 2 buttons on it. I saw the NavBar example, but this is not what I want. I have no problem in putting UIButton or UISegmentedControl or anything else that is derived from UIView on the navigation bar. However, I don't know how to put UIBarButtonItem as additional button :confused:

This really made me confused, because the only way I know to add buttons is to use titleView of my view controller. And this is really easy, you just have to add something that is derived from UIView as a subview of titleView. To my surprise, UIBarButtonItem is not derived from UIView, so it cannot be added as a subview, preventing a container designed to be used on tab bar to be placed on the boody tab bar.

I hope someone here can help me with it :o



beachdog
Aug 28, 2008, 09:04 AM
I did something like this once; unfortunately I later decided to change the code and I didn't save a code snippet showing how I did it. However, I *think* what I did is have a custom view for the right bar button, and I had that custom view be a segmented control. In that segmented control I then added my two UIBarButtonItems.

BTW, in my case it was suggested to me that a better UI approach than adding these two actions to the navbar was to create a toolbar down below for actions, and keep the navbar simply to navigation and basic edit operations. That is why I eventually decided against going this route.

kainjow
Aug 28, 2008, 12:12 PM
The reason they aren't views is because they're model objects. You are interacting with the navigation controller and its model objects, not the views and its subviews.

If you need to add a view as a button, use initWithCustomView: and set your button as the view.

Luke Redpath
Aug 29, 2008, 04:26 AM
Mmm. I find it hard to accept that *anything* that is part of the UI could be considered anything but a view.

kainjow
Aug 29, 2008, 07:38 PM
Mmm. I find it hard to accept that *anything* that is part of the UI could be considered anything but a view.

A color isn't a view... :p

Luke Redpath
Aug 30, 2008, 08:14 AM
No but its a property of a view.