Search code examples
iosswiftuibarbuttonitemuialertcontrolleruipopover

ActionSheet Source View BarButtonItem


I have a bar button item in the navigation bar that when pressed, will present a UIAlertController with the style as .ActionSheet. In the iPhone it appears just the way that I want. For the iPad I know I need to add

// For iPad, set the pop over bounds
var popOver = optionMenu.popoverPresentationController
popOver?.sourceView = button as UIView
popOver?.sourceRect = (button as UIView).bounds
popOver?.permittedArrowDirections = UIPopoverArrowDirection.Any

Does anyone know of a way to use the bar button item as the sourceView and the sourceRect? I would like the popover to point to the bar button item.


Solution

  • Just use popOver?.barButtonItem = myBarButtonItem