ios – 如何在Swift中的Alert中为按钮添加动作

ios – 如何在Swift中的Alert中为按钮添加动作,第1张

概述我是初级程序员.我正在尝试向Alert上的按钮添加 *** 作,但它不起作用.我只想测试警报按钮选项是否可以更改标签中的文本,但它不起作用.当然,我可以很好地看到警报和按钮,但点击按钮后没有任何反应. @IBOutlet var statusLabelAlert : UILabelvar alertTest = UIAlertView()@IBAction func alertButton(sen 我是初级程序员.我正在尝试向Alert上的按钮添加 *** 作,但它不起作用.我只想测试警报按钮选项是否可以更改标签中的文本,但它不起作用.当然,我可以很好地看到警报和按钮,但点击按钮后没有任何反应.
@IBOutlet var statusLabelAlert : UILabelvar alertTest = UIAlertVIEw()@IBAction func alertbutton(sender : AnyObject) {    alertTest.message = "Select one!"    alertTest.addbuttonWithTitle("1st")    alertTest.addbuttonWithTitle("2nd")    alertTest.addbuttonWithTitle("3rd")    alertTest.Title = "Test Alert"    alertTest.show()}func alertVIEw(alertVIEw: UIAlertVIEw!,clickedbuttonAtIndex buttonIndex: Int){    switch buttonIndex{    case 0:        statusLabelAlert.text = "1st"    case 1:        statusLabelAlert.text = "2nd"    case 2:        statusLabelAlert.text = "3rd"    default:        statusLabelAlert.text = "error"    }}
解决方法 你的clickedbuttonAtIndex方法是否正在调用?设置断点并调试代码.
您没有设置alertVIEw的委托.
@IBOutlet var statusLabelAlert : UILabelvar alertTest = UIAlertVIEw()alertTest.delegate = self   //set the delegate of alertVIEw@IBAction func alertbutton(sender : AnyObject) {alertTest.message = "Select one!"alertTest.addbuttonWithTitle("1st")alertTest.addbuttonWithTitle("2nd")alertTest.addbuttonWithTitle("3rd")alertTest.Title = "Test Alert"alertTest.show()}func alertVIEw(alertVIEw: UIAlertVIEw!,clickedbuttonAtIndex buttonIndex: Int){switch buttonIndex{case 0:    statusLabelAlert.text = "1st"case 1:    statusLabelAlert.text = "2nd"case 2:    statusLabelAlert.text = "3rd"default:    statusLabelAlert.text = "error"}}
总结

以上是内存溢出为你收集整理的ios – 如何在Swift中的Alert中为按钮添加动作全部内容,希望文章能够帮你解决ios – 如何在Swift中的Alert中为按钮添加动作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1099202.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存