
@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中为按钮添加动作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)