UIPopover contentSize is changing in runtime

176 Views Asked by At

We are facing an issue where popover size is getting changed when a UIActionSheet style of alertController is used inside a popover. This is happening after we upgraded our code base iOS13

Sample Code: https://github.com/Sundeep-manne/UIPopover.git

1

There are 1 best solutions below

2
Radek Wilczak On

I think this is Apple bug. I experience it on Xcode 11.1, but on Xcode 11.2.1 when displaying the ActionSheet I'm getting the crash:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController () of style UIAlertControllerStyleActionSheet from UINavigationController (). The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'

So the answer is: to use ActionSheet on iPad you need to provide sourceView and sourceRect in popoverPresentationController of your UIAlertController. More info: https://medium.com/@nickmeehan/actionsheet-popover-on-ipad-in-swift-5768dfa82094

Apple docs:

On iPad, UIKit requires that you display an action sheet inside a popover.

https://developer.apple.com/documentation/uikit/windows_and_screens/getting_the_user_s_attention_with_alerts_and_action_sheets