UIAlertController的一些细节.md

327 阅读1分钟

如果是iPad以actionSheet弹出需要正确设置

class UIViewController : UIResponder {
    var popoverPresentationController: UIPopoverPresentationController? { get }
}

class UIPopoverPresentationController : UIPresentationController {
    var sourceView: UIView? { get set }
}
/// xxxx一般为对应的按钮或者别的子view
vc.popoverPresentationController.sourceView = xxxx

否则会crash,下边为报错

Your application has presented a UIAlertController (<UIAlertController: 0x12b2eda00>) of style UIAlertControllerStyleActionSheet from xxxxx.NavigationController (<xxxxx.NavigationController: 0x10a88b800>). 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.