Try the search, it's linked to some great forums

Thursday, July 28, 2011

Popover's & their delegate for iPads

The following code is a simple implementation of a popover using a separate view controller & xib file.  First the instantiation & display code;
    InfoViewController *popoverView = [[InfoViewController alloc] init];
    popoverView.delegate = self; 
// Creates the popoverController object
    infoPopover = [[UIPopoverController alloc] initWithContentViewController:popoverView];
    [infoPopover setDelegate:self];
    [infoPopover presentPopoverFromRect:CGRectMake(512, 200, 10, -30) inView:self.view permittedArrowDirections:0 animated:NO];
    [infoPopover setPopoverContentSize:CGSizeMake(400, 500)];

and then instructions;
in PopoverViewController
the .xib file
  • in the view change the status bar = None, so that you can resize the screen
  • add controls as you like
the .h file:
  • add IBOutlet IBActions to match the xib file
  • connect them to the xib objects
  • add delegate protocol & method definitions at the bottom of the file
  • add the delegate property using assign & id
.m file:
  • synthesize & release the popover controls
In the delegate 
the .h file
  • add the conforms to
  • add a UIPopoverController property use assign for the property
  • Add an IBAction show button to display the popover
the .m file
  • Add the delegate's methods
See ZenDesk for a nice implementation