以下代码在调用.present时为我提供了一个sigabort:
func alert(message: String, title: String = "") {
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { action in
switch action.style {
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}}))
alertController.present(alertController, animated: true, completion: nil)
}
帮助!我没有得到这个!
答案 0 :(得分:0)
您正在调用alertController而不是视图。更改它以引用父UIViewController的存在(...)。
func present(_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil)
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-present