In iPad, we have a new control called UIPopover. This control shows up as an overlay in the screen with a UIViewController or UIView in it. But I came across a problem of showing title with header bar in Popover control. Then came across a set of solution, which solved my problem.

The logic behind this implementation is:

  • Create a view controller class (here demoViewController).
  • Create an object of navigation controller (here demoNavController) and initialize it with view controller as it’s RootViewController.
  • Create an object of UIPopoverController (here demoPopup) and initialize it with navigation controller as it’s ContentViewController
  • Set delegate of popover control to current class and set title of navigation controller with desired string.
  • Find bounds of a button (or any control, from where you want to present the popover control) and show the control from this bound.

And that’s it.

Here is the code for this implementation:

if(trainnePopup == nil)
{
DemoViewController *demoViewController = [[DemoViewController alloc]initWithNibName:@”DemoViewController” bundle:[NSBundle mainBundle]];

UINavigationController *demoNavController = [[[UINavigationController alloc] initWithRootViewController:demoViewController] autorelease];

UIPopoverController *demoPopup = [[UIPopoverController alloc]initWithContentViewController:demoNavController];
[demoPopup setPopoverContentSize:CGSizeMake(demoViewController.view.frame.size.width, demoViewController.view.frame.size.height)];
[demoViewController release];
demoPopup.delegate = self;
demoPopup.contentViewController.title=@”Demo Popup”;

}

// Below lines are used to show the arrow of the popover control
CGRect popoverRect= [self.view convertRect:[buttonCtrl bounds]
fromView:[buttonCtrl superview]];

[demoPopup presentPopoverFromRect:CGRectMake(335, 258, 100, 100)
inView:[self view] permittedArrowDirections: UIPopoverArrowDirectionUp
animated:YES];

Cheers!


Leave a Reply

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