gpt4 book ai didi

ios - UIAlertController addAction 不起作用

转载 作者:行者123 更新时间:2023-11-29 01:07:49 27 4
gpt4 key购买 nike

所以 UIAlertController 正确地在屏幕上显示警报,但在 xCode 模拟器中按 ok 什么都不做,它不会离开警报。 alert view image

    func displayAlertMessage(userMessage:String) {

let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);

let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil);

myAlert.addAction(okAction);

self.presentViewController(myAlert, animated: true, completion: nil);

}

最佳答案

将 UIAlertActionStyle.Default 更改为 UIAlertActionStyle.Cancel

func displayAlertMessage(userMessage:String) {

let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);

let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil);

myAlert.addAction(okAction);

self.presentViewController(myAlert, animated: true, completion: nil);

}

如果你想做点什么就可以

 let okAction = UIAlertAction(title: "OK", style: .Default) { (action) in
//do whatever you want to do here
// for e.g dismiss view controller or segue your view controller etc.
}

关于ios - UIAlertController addAction 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36139004/

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