Search code examples
cocoa-touchipaduitableviewuisplitviewcontrolleruipopovercontroller

Navigation Bar in UIPopover


in my splitviewcontroller iPad app I show a custom popover (which loads the rootviewController). How to show not only the table view, but also a navigationbar on top of it (to show the table title "Categories").

Here is my app:

enter image description here

My code to show the popover:

- (IBAction)showPopover:(UIButton *)sender {
if([self.popoverController isPopoverVisible])
{
    [self.popoverController dismissPopoverAnimated:YES];
    return;
}

// Build a custom popover view
TemplatesAppDelegate *delegate = (TemplatesAppDelegate*)[[UIApplication sharedApplication] delegate];

// Create a popover controller
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:delegate.rootViewController] autorelease];

// Present the popover view non-modal at the pressed button's position
[self.popoverController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

Solution

  • If you want a whole UINavigationController with all the functionalities, you can do like

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:delegate.rootViewController];
    
    self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];
    [navController release];
    

    Or if you want just a navigation bar you can add to your popovercontroller.

    UINavigationBar *tableViewNavigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
    [self.popoverController addSubView:tableViewNavigationBar];
    

    I didn't tested the code, but it should work.