gpt4 book ai didi

ios - UIAlertView 在 Swift 中不工作

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:34 25 4
gpt4 key购买 nike

当我快速运行这段代码时,我不知道为什么应用程序会在“alertView.show()”部分显示一个断点而终止,请有人帮助我。

var alertView = UIAlertView(
title: "Hey",
message: "Hello",
delegate: self,
cancelButtonTitle: "Cancel"
)
alertView.show()

最佳答案

来自 Xcode 6.0 UIAlertView 类:

UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead.

在 swift(iOS 8 和 OS X 10.10)上,你可以这样做:

var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel, handler:handleCancel))
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in
println("User click Ok button")
}))
self.presentViewController(alert, animated: true, completion: nil)

func handleCancel(alertView: UIAlertAction!)
{
println("User click cancel button")
}

如果您想在“ActionSheet”中使用而不是“Alert”,您只需更改 UIAlertControllerStyle,例如:

var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.ActionSheet)

关于ios - UIAlertView 在 Swift 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24084521/

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