Search code examples
iosobjective-cuiviewcontrolleruicontroluipopoverpresentationcontroller

Display an UIPopoverPresentationController from a UIControl?


I am writing a UIControl. I need to display a popover when the user touches an area of the control. But of course the usual code:

[self presentViewController:self.popover animated:YES completion:nil];

does not work because we are in a UIControl, not in a UIViewController. How can I display a popover from a UIControl?


Solution

  • You should use rootViewController to present it.

    Use UIApplication.sharedApplication.delegate.window.rootViewController instead of self

    [UIApplication.sharedApplication.delegate.window.rootViewController presentViewController:self.popover animated:YES completion:nil];