Search code examples
iosuinavigationcontrolleruipopovercontrolleruitoolbar

UIToolbar Items are not showing in popover


I am trying to show a custom tableview inside a popover view in my iPad App. This is working fine. I wanted to add buttons on toolbar (at the bottom of tableview). Toolbar is shown empty. Any suggestion?

Note that following code is triggered when user touches the button in main view controller.

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.customTableViewController];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"item 1" style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"item 2" style:UIBarButtonItemStylePlain target:nil action:nil];

[navigationController setToolbarHidden:NO];
navigationController.navigationBar.topItem.title = @"Some Title";

NSArray *array = [[NSArray alloc] initWithObjects:item1, item2, nil];
[navigationController setToolbarItems:array];

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popoverController = popover;
popoverController.delegate = self;

[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Solution

  • I'm hitting a similar issue, the tableview shows fine in the popover, but the buttons below are not visible. I'll let you know if I figure something out.

    EDIT: My issue was that I was re-sizing the popover, and the buttons were being pushed out of the view. I fixed this by changing the autosizing to lock the position relative to the bottom of the frame. To do this, look at your xib in interface builder, go to the Ruler tab on the upper right and use the Autosizing GUI. For mine this meant that only the bottom anchor was selected on the GUI.