Mutliple UINavigationBars in a UITableViewController

Discussion in 'iOS Development' started by masaj, May 15, 2009.

  1. masaj

    masaj New Member

    Joined:
    Apr 27, 2009
    Messages:
    13
    Likes Received:
    0
    Is there an easy way to get multiple UINavigationBars in a UITableViewController view?

    If I do:
    Code:
    [self.navigationController.view addSubview: otherBar]
    
    it replaces my existing bar.

    The view in my UITableViewController is a UITableView. If I add the bar to:
    Code:
    [self.view addSubview: otherBar]
    
    The bar is added to the table itself. It renders on top of the first UITableViewCell of the table i.e. hides it, and it also scrolls with the view. I don't want either of those things.
  2. DomMaiocchi

    DomMaiocchi New Member

    Joined:
    Jan 22, 2009
    Messages:
    62
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    I'm not sure why you would want two. What are you trying to achieve?
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    You could easily do something like this.

    Code:
    UINavigationController *outerNavigationController = [[[UINavigationController alloc] initWithRootViewController:[[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease]] autorelease];
    Alternatively, don't use a UITableviewController. Instead, use a UIViewController with a UITableView planted on top of the main view. Reset the size of the table to account for the second navigation bar you will also be plopping down.

    Although, why not just think of a better UI? I don't mean that insultingly or condescendingly, but surely you can think of something better than two UINavigationBars?
  4. DomMaiocchi

    DomMaiocchi New Member

    Joined:
    Jan 22, 2009
    Messages:
    62
    Likes Received:
    0
    Device:
    iPhone 4 (Black)

    I couldn't have said it better myself!
  5. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    I mean you COULD replace that navigation bar with a UIToolbar
  6. masaj

    masaj New Member

    Joined:
    Apr 27, 2009
    Messages:
    13
    Likes Received:
    0
    Thanks for the replies folks.

    Well it's more of a status bar than a nav bar. It does have a few buttons but mainly it displays data.

    Right, this is what I ended up using.
    I searched and found this thread:
    http://forums.macrumors.com/showthread.php?p=5954991

    And ended up setting the view to a wrapper view (totalView) which holds both the tableView (tableView) and the UIToolbar (buttonView)

    Code:
        UIView *totalView =
            [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        [totalView addSubview: buttonView];
        [totalView addSubview: tableView];
        self.view = totalView;
    
    The example looked like this:
    http://forums.macrumors.com/showpost.php?p=6090142&postcount=14

    I wanted mine along the top, so I just changed the CGRect coords passed to initWithFrame: of the UIToolbar.

    Thanks everyone for the responses.

Share This Page