Search code examples
iosswiftiphonealertuialertcontroller

Action Sheet is not working in ipad ios 13.6


My app uses UIAlertController for both ActionSheet and Alert. It works fine on iOS 13.4 in iPad, but if I run the code from my iOS 13.6 device, this is not working properly in iPad 12.9 ios 13.6.

    let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle: 
    UIAlertController.Style.actionSheet)
       alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default, 
    handler: { (res) in
        self.btnClickedCamera(tag:2)
    }))
    alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default, 
    handler: { (res) in
        self.btnClickedGallery(tag:2)
    }))
    alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
        
    }))
    if let popoverPresentationController = alert.popoverPresentationController {
        popoverPresentationController.sourceView = sender
        popoverPresentationController.sourceRect = sender.bounds
    }
    self.present(alert, animated: true, completion: nil)

Solution

  • I have tried your code on iPhone(Device:- iPhone 11 Pro 13.6) and iPad(iPad pro (12.9- 4th generation) both and it works. But If you said, I have changed some popover frame, Use the following code:-

       let alert = UIAlertController(title: "Select Image", message: nil, preferredStyle:
        UIAlertController.Style.actionSheet)
           alert.addAction(UIAlertAction(title: "Camera", style: UIAlertAction.Style.default,
        handler: { (res) in
            self.btnClickedCamera(tag:2)
        }))
        alert.addAction(UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default,
        handler: { (res) in
           self.btnClickedGallery(tag:2)
        }))
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (res) in
    
        }))
        if let popoverPresentationController = alert.popoverPresentationController {
    
            popoverPresentationController.sourceRect = sender.frame
            popoverPresentationController.sourceView = self.view
    
        }
        self.present(alert, animated: true, completion: nil)
    
    }