2 of 3 UIAlertAction show up

I'm displaying an action sheet on my iPad using the struture below. Only the last two actions are appearing. The first one, with the style of .cancel, isn't being displayed. Any idea what could be going on?



DispatchQueue.main.async {
    var message = ...
    let alert = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet)

    message = ...
    alert.addAction(title: message, style: .cancel) { }
         
    message = ...
    alert.addAction(title: message, style: .destructive) { }

    message = ...
    alert.addAction(title: message, style: .default) { }
         
    if let p = alert.popoverPresentationController {
        p.sourceView = rootVC.view
        p.sourceRect = CGRect(x: rootVC.view.center.x, y: rootVC.view.center.y, width: 10, height: 10)
    }    
         
    rootVC.present(alert, animated: true)
}



extension UIAlertController {
    func addAction(title: String?, style: UIAlertActionStyle, handler: ((UIAlertAction) -> Void)? = nil) {
        addAction(UIAlertAction(title: title, style: style, handler: handler))
    }
}

Have you enough room vertically to display everything ?


Could you try to comment out the second action

alert.addAction(title: message, style: .destructive) { }


To see if destructive shows

It's on an ipad, so should be plenty of room. If I comment out like you said it just shows accept. If I change that first one from cancel to default then it shows fine. For some reason it just doesn't want to show with a style of cancel.

I tried an lert with a combination of 3 buttons (.cancel, .destructive and .default) and they show without problem.


So the "problem" comes from alert.popoverPresentationController.

Now I remember that, when you have a popover, the cancel is not displayed. Because clicking outside the popover dismisses the alert, no need for .cancel !


And it is documented here :

h ttps://developer.apple.com/documentation/uikit/windows_and_screens/getting_the_user_s_attention_with_alerts_and_action_sheets

If your set of actions includes a button configured with the UIAlertActionCancel style, UIKit removes that button when displaying your action sheet in a popover. Tapping anywhere outside of the popover has the same effect as tapping the Cancel button, including calling your action handler.

2 of 3 UIAlertAction show up
 
 
Q