UIAlertController is Crashed (iPad)

后端 未结 10 1774
长情又很酷
长情又很酷 2020-12-13 17:58

I am using Xcode 6 to develop an iOS Application.

When I used UIAlertController, it can be worked well on iPhone 6 simulator, but crashes on iPad simula

10条回答
  •  难免孤独
    2020-12-13 18:49

    I use this handy extension to create action sheets that never crash

    extension UIAlertController {
    
        class func actionSheetWith(title: String?, message: String?, sourceView: UIView?, sourceFrame: CGRect?) -> UIAlertController {
            let actionController = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
            if actionController.responds(to: #selector(getter: popoverPresentationController)) {
                actionController.popoverPresentationController?.sourceView = sourceView ?? StoryboardHelper.tabBarControllerTopController()?.view
                actionController.popoverPresentationController?.sourceRect = sourceFrame ?? CGRect(x: 0, y: 0, width: 0, height: 0)
            }
            return actionController
        }
    
    }
    

提交回复
热议问题