1

I am creating iPhone application by using storyboard. In this, how to create a popup on storyboard and how to add and dismiss this popup on viewcontroller.

Popup Sample Image:

enter image description here

i want to add popup in storyboard like this:

enter image description here

Hari Babu
  • 891
  • 1
  • 9
  • 22

1 Answers1

0

You might create it like this (don't forget to add <UIPopoverControllerDelegate> to presenting view controller class)

UIStoryboard* storyboard = [UIStoryboard storyboardWithName : @"MainStoryboard" bundle : nil];
    MyCustomPopoverContentVC* customContentViewController = [storyboard instantiateViewControllerWithIdentifier : @"MyCustomPopoverContentVC"];

// initialize popover controller with content view controller
UIPopoverController* popoverController = [[UIPopoverController alloc] initWithContentViewController: anyCustomViewController];
popoverController.delegate = self;
// change popoverContentSize here
CGRect contentFrame = CGRectMake(0.0, 0, 500.0, 500.0);
popoverController.popoverContentSize = contentFrame.size;
// present popover controller
[popoverController presentPopoverFromRect: _buttonRectForPopoverController inView: self.view permittedArrowDirections: UIPopoverArrowDirectionUp animated: YES];

and somewhere else in your presenting view controller class an example `UIPopoverControllerDelegate' method:

// refreshes the rect from where the popover is shown after interface orientations.
// this method is necessary and recommended by apple's documentation
- (void) popoverController : (UIPopoverController*) popoverController willRepositionPopoverToRect : (inout CGRect*) rect inView : (inout UIView*__autoreleasing*) view
{
    *rect = _buttonRectForPopoverController;
}
anneblue
  • 706
  • 4
  • 21