Introduction to UIPopoverController in iOS 6

How to integrate UIPopoverController in iOS 6

In this tutorial i am going to explain about the UIPopoverController in iOS 6.

                 According to apple developer guide documentation, the UIPopoverController class is used to manage the presentation of content in a popover. The popover content is layered on top of your existing content in a special type of window. The popover remains visible until the user taps outside of the popover window or you explicitly dismiss it. Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.To display a popover, create an instance of UIPopoverController class and present it using one of the appropriate methods. When initializing an instance of UIPopoverController class, you must provide the view controller that provides the content for the popover. Popovers normally derive their size from the view controller they present.

 

Tasks

[box type=”shadow”]

Initializing the Popover

 Configuring the Popover Attributes

 Getting the Popover Attributes

 Presenting and Dismissing the Popover

 Customizing the Popover Appearance

[/box]

So that’s about the introduction about UIPopoverController.Now we can play a live implementation of UIPopoverController.

Step 1:
so create a new XCode iPad iOS 6 project and name it as UIPopoverController Example.
UIPopoverController example

Step 2:
Drag and drop UIButton to the viewcontroller.xib and rename it as Show Popover, and hook up the corresponding IBAction to show the popover.

showPopOver
Step 3:
Create a productView controller to show it inside the pop Over

Step 4:
Create instance of UIPopoverController

 

  
-(IBAction)showPopOver:(id)sender{
    
    UIButton *btn =sender;
    ProductsViewController *productsView =[[ProductsViewController alloc] initWithNibName:@"ProductsViewController" bundle:nil];
    popOver =[[UIPopoverController alloc] initWithContentViewController:productsView];
    [popOver presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    
    [productsView release];
    
}

popover

UIPopoverController setting up the arrow directions.

  [popOver presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  [popOver presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
  [popOver presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
    [popOver presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUnknown animated:YES];
    [popOver presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

you can download the entire source code of UIPopOverController from here

Leave a Reply

Your email address will not be published. Required fields are marked *