How to create Popover in ipad?

kernel.roy picture kernel.roy · Aug 4, 2011 · Viewed 31.4k times · Source

I want to develop a popover in my iPad application. A UIButton trigger will call the popover and that popover will contain a UITableViewController.

First I need a popover.

Need some example code or direction or link.

Thanks in advance.

Answer

Prerna picture Prerna · Aug 10, 2011

in your viewcontroller on the button action write this code:

- (IBAction)openAllRhymes:(id)sender{
    UIButton *button = (UIButton*)sender;

    PopupTableView *tableViewController = [[PopupTableView alloc] initWithStyle:UITableViewStylePlain];


    popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
    [popover presentPopoverFromRect:CGRectMake(button.frame.size.width / 2, button.frame.size.height / 1, 1, 1) inView:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    [tableViewController release];
}

Now you have created a tableview for popover in that tableviewcontroller write:

self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(108,400);