UIBarButtonItem not derived from UIView???

Discussion in 'iOS Programming' started by lawicko, Aug 28, 2008.

  1. macrumors member

    Joined:
    Jul 17, 2008
    #1
    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

    Joined:
    Aug 10, 2008
    #2
    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

    kainjow

    Joined:
    Jun 15, 2000
    #3
    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

    Joined:
    Nov 9, 2007
    #4
    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

    kainjow

    Joined:
    Jun 15, 2000
    #5
    A color isn't a view... :p
     
  6. macrumors 6502a

    Joined:
    Nov 9, 2007

Share This Page