快速显示 UIAlertView 时出错 [英] Error showing a UIAlertView in swift
本文介绍了快速显示 UIAlertView 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的 swift 应用程序中显示 UIAlertView
Im trying to show a UIAlertView in my swift App
alert = UIAlertView(title: "",
message: "bla",
delegate: self,
cancelButtonTitle: "OK")
alert!.show()
=> BAD_ACES 错误:-[_UIAlertViewAlertControllerShim initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:]()
=> BAD_ACESS error in: -[_UIAlertViewAlertControllerShim initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:] ()
所以我怀疑自己.我把它设置为零
so I suspected self. I set it to nil
alert = UIAlertView(title: "",
message: "bla",
delegate: nil,
cancelButtonTitle: "OK")
alert!.show()
=> ARM_DA_ALIGN 错误:-[_UIAlertViewAlertControllerShim initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:]()
=> ARM_DA_ALIGN error in: -[_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 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文