UIAlertController replacement

Here is a known UIAlertController crash on iPad:

******Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0xaf71c80>) of style UIAlertControllerStyleActionSheet. 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[![enter image description here][1]][1] present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'

Please use UIPadAlertController to create UIAlertController, provide sourceView and sourceRect on iPad version as per UI design document.

The UIPadAlertController fixed crash issue even not provide sourceView on iPad, it will use .alert style if you have not provide sourceView.

Code example:

import TBaseFramework

class ViewController: UIViewController, EventHandler, StoreSubscriber {
    
    private var tableView: UITableView!
    var debugTitleView: UILabel?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        // following code will not crash even on iPad
        let alert = UIPadAlertController.alertController(title: "title", message: "message", preferredStyle: .actionSheet, sourceView: nil, sourceRect: nil)
        

Leave a Reply

Your email address will not be published. Required fields are marked *