Search code examples
iosuinavigationcontrollerios7uipopovercontroller

UINavigationController inside UIPopover navigation buttons not showing


I have an iPad app with a UIPopoverController with a UINavigationController nested inside it, so that it can have a title bar with "Done" and "Cancel" buttons. In iOS7 there seems to be some glitch that the buttons aren't appearing by default (sometimes they reappear if I rotate the device and back again, or I think if I switch to another app and then back again). Weirdly, you can still interact with them, you just can't see them! Has anybody else experienced this, and if so, do you have a workaround?

KNMultiItemSelector * selector = [[KNMultiItemSelector alloc] initWithItems:sortedItems
                                                           preselectedItems:nil
                                                                      title:@"Select contacts"
                                                            placeholderText:@"Search"
                                                                   delegate:self];
selector.useTableIndex = YES;
selector.allowSearchControl = YES;
selector.modalPresentationStyle = UIModalPresentationFormSheet;

UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:selector];

selector.view.frame = CGRectMake(0, 0, self.view.frame.size.width - 40, self.view.frame.size.height - 40);
nav.contentSizeForViewInPopover = CGSizeMake(self.view.frame.size.width - 40, self.view.frame.size.height - 40);
self.popover = [[UIPopoverController alloc] initWithContentViewController:nav];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:CGRectMake(self.view.frame.size.width * 0.5 + self.tableView.contentOffset.x, 20 + self.tableView.contentOffset.y, 0, 0)
                                        inView:self.view
                          permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    

The KMultiItemSelector initWithItems: method initialises the right button like so:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(didFinish)];

Solution

  • It turns out this can happen if you create your popover / navigation controller / embedded view in a thread that is not the main thread. Move it all into the main thread and magically the buttons reappear.