2

There are a lot of questions and answers on Stack Overflow about this but they are just valid for iOS 8 and before.

iOS 9 deprecated a lot of things and the answers on SO did not work anymore.

Said that, I am presenting a popover by performing a segue like this

[self performSegueWithIdentifier:@"myPopover" sender:self];

This segue is created between the current viewController and the viewController used by the popover. There is no button involved. The popover is anchored to a view.

The problem is that on prepareForSegue:identifier

[segue destinationViewController]

is a UIViewController and

[[segue destinationViewController] popoverPresentationController]

is the new UIPopoverPresentationController and this object does not offer a dismiss api anymore.

Instead, we are supposed to use

[self dismissViewControllerAnimated:YES completion:nil];

to dismiss the popover but this has no effect for me.

My situation is this: I have a popover with a text field. I want to dismiss the popover if the user hides the keyboard.

So I did this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

and then

- (void)keyboardWillHide:(NSNotification *)notification {
  [self dismissViewControllerAnimated:YES completion:nil];
}

but this has no effect at all.

I have also tried to create an unwind segue inside the popover viewController and call that from the presenting view controller but that makes the app crash.

Duck
  • 34,902
  • 47
  • 248
  • 470
  • see this link may be helps you http://stackoverflow.com/questions/28719306/dismissviewcontrolleranimatedyes-completionnil-not-working-for-ios-device – Anbu.Karthik Dec 09 '15 at 10:47
  • Or this http://stackoverflow.com/questions/33468698/how-to-detect-when-a-popover-is-dismissed-in-ios-9 – iAnurag Dec 09 '15 at 10:49
  • @iAnurag - the question you mention tells me nothing about what I have asked... "how to **dismiss**" not present. – Duck Dec 09 '15 at 11:02
  • @Anbu.Karthik - `self presentingViewController` gives me nil inside the popover view controller. – Duck Dec 09 '15 at 11:03
  • What class is your `keyboardWillHide:` method in? – jcaron Dec 09 '15 at 11:27
  • Just tried it and it all seems to work perfectly. What is your view controller hierarchy (navigation controllers, etc.)? Are you properly calling `dismissViewControllerAnimated:completion` on the same view controller that presented the popover? Make sure there isn't a mixup between child view controller and navigation controller. You can also log the popover view controller's `presentingViewController` to check. – jcaron Dec 09 '15 at 11:34

1 Answers1

3

Just tried it and it all seems to work perfectly.

  • What is your view controller hierarchy (navigation controllers, etc.)?
  • Are you properly calling dismissViewControllerAnimated:completion: on the same view controller that presented the popover?
  • Make sure there isn't a mixup between child view controller and navigation controller.
  • You can also log the popover view controller's presentingViewController to check.
jcaron
  • 17,302
  • 6
  • 32
  • 46