Monday 17 October 2011

How to use UIPopOverController in iPad

             How to use UIPopOverController in iPad

UIPopOverController is used to show the Content as a popover, it is used in iPad to display a content temporarily. PopOver will be displayed over the existing UIView or UIButton or UIBarButton as a special type of window, Popover will remains visible until user touch outside the popover window or you dismiss programmatically.

Create TableViewController  for popover content
    UITableViewController  *tbView = [[UITableViewController alloc]initWithStyle:UITableViewStyleGrouped]; 
    tbView.delegate = self;

Create and show PopOverController :-
   UIPopoverController *listPopover = [[UIPopoverController alloc]initWithContentViewController:tbView];   //initialized with tableview controller
//displaying popover on top of UIView inherited classes
    [listPopover presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:yourUIButtonObject permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

//for dispalying popover in UIBarbuttonItem
    [listPopover presentPopoverFromBarButtonItem:yourBarbuttonItemObject 
                                  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Dismiss PopOverController :-
      [listPopover dismissPopoverAnimated:YES];   

Can set the popover content size in two methods
    1) popoverContentSize property
    2)setPopoverContentSize:animated: method  ( particularly effective when need to animate changes to     the popover’s size)

Note :-
  should handle the orientation carefully when your barbutton hidden.



No comments:

Post a Comment