Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customising the titleView in a UIPopoverController

On an iPad application, I want to be able to have multiple buttons in the top bar of a popover. I'm launching it like this:

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];

pop = [[UIPopoverController alloc] initWithContentViewController:nc];
[pop presentPopoverFromRect:CGRectInset([tableView rectForRowAtIndexPath:indexPath], 10, 10)
                     inView:tableView
   permittedArrowDirections:UIPopoverArrowDirectionAny
                   animated:YES];
pop.delegate = self;
[nc release];

In the viewDidLoad I want to set the titleView to contain multiple UIBarButtonItems. This is ok on a normal UINavigationController but I need to be able to do this and keep the custom style of the navigation bar on the popover.

I have tried setting the rightBarButtonItem to have a toolbar that contains buttons, but they take the format of the toolbar, which itself will not take the format/style of the popover.

like image 866
Lee Avatar asked May 18 '11 09:05

Lee


1 Answers

It's a bit hackish, but you can create a truly transparent UIToolbar by subclassing and overriding drawRect: with an empty method. This will still draw the UIBarButtonItems on the toolbar, but not the toolbar itself.

Then, as Nils describes, you can create a bar button item out of the custom toolbar instance and add it as the rightBarButtonItem.

like image 113
Benjamin Mayo Avatar answered Sep 23 '22 02:09

Benjamin Mayo