gpt4 book ai didi

uialertview - 快速显示 UIAlertView 时出错

转载 作者:IT王子 更新时间:2023-10-29 05:38:51 25 4
gpt4 key购买 nike

我试图在我的 swift 应用程序中显示一个 UIAlertView

    alert = UIAlertView(title: "",
message: "bla",
delegate: self,
cancelButtonTitle: "OK")
alert!.show()

=> BAD_ACESS 错误: -[_UIAlertViewAlertControllerShim initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:] ()

所以我怀疑自己。我把它设置为零

    alert = UIAlertView(title: "",
message: "bla",
delegate: nil,
cancelButtonTitle: "OK")
alert!.show()

=> ARM_DA_ALIGN 错误: -[_UIAlertViewAlertControllerShim initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:] ()


完整代码

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UIAlertViewDelegate {

@lazy var window = UIWindow(frame: UIScreen.mainScreen().bounds)
@lazy var locationManager = CLLocationManager()
var alert: UIAlertView? = nil

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//setup dummy window
self.window.backgroundColor = UIColor.whiteColor()
self.window.rootViewController = UIViewController()
self.window.makeKeyAndVisible()

alert = UIAlertView(title: "",
message: "bla",
delegate: nil,
cancelButtonTitle: "OK")
alert!.show()

return true
}
}

怎样做才是对的? :)

最佳答案

swift 5

你应该这样做:

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Button", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)

关于uialertview - 快速显示 UIAlertView 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24040519/

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