Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss UIPopover from a button in the Popover with IOS 8 XCode 6 beta

I managed to display popover using UIPopoverPresentationController as the UIPopoverController got deprecated in IOS 8, but now I want to dismiss the popover on tap of button from the popover.

How can it be dismissed?

like image 428
user3919517 Avatar asked Dec 26 '22 05:12

user3919517


1 Answers

Use presentingViewController property of the UIViewController to dismiss. Eg: To present

  vc.modalPresentationStyle = UIModalPresentationPopover;
  vc.preferredContentSize  = aPreffferedSize;
  UIPopoverPresentationController *popcontroller = vc.popoverPresentationController;
  popcontroller.barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
  popcontroller.permittedArrowDirections = UIPopoverArrowDirectionAny;
  popcontroller.delegate = self;

  [self presentViewController:vc animated:YES completion:nil];

To dismiss programatically,

  [[vc presentingViewController] dismissViewControllerAnimated:YES completion:NULL];

Hope this helps.

like image 171
Abhijit Avatar answered Dec 28 '22 08:12

Abhijit