1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

UIBarButtonItem not derived from UIView???

Discussion in 'iPhone/iPad Programming' started by lawicko, Aug 28, 2008.

  1. macrumors member

    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 :eek:
  2. macrumors member

    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.
  3. Moderator emeritus


    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.
  4. macrumors 6502a

    Mmm. I find it hard to accept that *anything* that is part of the UI could be considered anything but a view.
  5. Moderator emeritus


    A color isn't a view... :p
  6. macrumors 6502a

    No but its a property of a view.

Share This Page