iPhoneOS SDK – iPad Popover Controller
19/04/2010
The iPad Popover control is possibly the least publicized feature of the iPhoneOS SDK, but becomes critical to in app actions and workflows. This is because the Popover Controller can show a small UIView of controls and more importantly save the user from having the whole screen change navigation hierarchy. A simple popover for example, can be used to edit a textfield, or change a date really quickly. In an iPhone app, this would typically be done by sending the user to a ‘DetailView’ where the setting/property can be change, whereas on the iPad this is highly discouraged. I am going to go through a quick popover example today, and on monday I will post a fantastic iPad user template.
1. Understanding the context
First, you need to know where a popover should be used. I can’t say much more than whats above. Use the apple apps, use the other top 100 apps, see how they use the popover controller. This will give you a feel of what it should do.
2. Some Code
Firstly, your main view controller {.h} needs a <UIPopoverControllerDelegate> declaration.
In your main view controller, add the following to the @interface (.h file)
//PopoverViewController
UIPopoverController *popoverController;
and just before @end add an IBAction:
- (IBAction)popOverViewCall:(id)sender;
Create a New View & ViewController {.h/.m} files and place them in your project. This is the actual popover that will come up. Place controls how ever you see fit. I call this popover controller MyViewControllerForPopover. Add an include of this file to your main view controller, eg:
#import “FirstDetailViewControllerPopOverControl.h”
In MyViewControllerForPopop {.m file}, add the following code:
-(void)viewDidAppear:(BOOL)animated
{
self.contentSizeForViewInPopover = CGSizeMake(320,320);
}
This sets the size of the popover for showing.Go into interface builder and add a couple controls to ensure you know when it works.
And finally in your main view controller {.m file}, add the IBAction:
-(IBAction)popOverViewCall:(id)sender{
FirstDetailViewControllerPopOverControl *myViewControllerForPopover = [[FirstDetailViewControllerPopOverControl alloc] initWithNibName:@”FirstDetailViewControllerPopOverControl” bundle:nil ];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:myViewControllerForPopover];
self.popoverController = popover;
popoverController.delegate = self;
[popover release];
[myViewControllerForPopover release];
CGPoint point = {200,200}; // Place to put on screen
CGSize size = {600,600}; // A content range (see apple docs)
[popoverController presentPopoverFromRect:CGRectMake(point.x, point.y, size.width, size.height)
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Add a button on your main view controller to call the IBAction. That covers it! One of the new features in iPhoneOS3.2 for iPad. See the screenshots for how it should look, code is downloadable below.

![]() |
 |

