gpt4 book ai didi

swift - 显示 Swift 4 错误警报

转载 作者:行者123 更新时间:2023-11-30 11:40:33 24 4
gpt4 key购买 nike

以下代码在调用 .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)
}

救命啊!我不明白这个!

最佳答案

您正在调用alertController 的present,而不是 View 的present。将其更改为引用父 UIViewController 的present(...)。

func present(_ viewControllerToPresent: UIViewController, 
animated flag: Bool,
completion: (() -> Void)? = nil)

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-present

关于swift - 显示 Swift 4 错误警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49335557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com