[英]How to disable a UIButton and send a UIAlertView message
I am trying to disable a menu button is the array is shows is empty. 我正在尝试禁用菜单按钮,因为数组显示为空。
This is my code. 这是我的代码。
@IBAction func likedmenubuttontouched(sender: AnyObject) {
if Globals.likedArray.isEmpty {
likedMenuButton.userInteractionEnabled = false
let ac = UIAlertController(title: "No liked quotes yet", message: "No liked quotes have been chosen, go explore!", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
return
} else {
likedMenuButton.userInteractionEnabled = true
}
}
And in ViewDidLoad() 并在ViewDidLoad()中
likedMenuButton.userInteractionEnabled = false
I have managed to disable the button, but I want to send a message alerting the user why the button is disabled, otherwise, its a little confusing. 我已经设法禁用了该按钮,但是我想发送一条消息,警告用户为什么该按钮被禁用,否则,会有些混乱。
How would I go about doing this? 我将如何去做呢?
Thanks. 谢谢。
As by default the the user Interaction is true you need not to make it true 默认情况下,用户交互为true,您无需使其为true
@IBAction func likedmenubuttontouched(sender: AnyObject) {
if Globals.likedArray.isEmpty {
let ac = UIAlertController(title: "No liked quotes yet", message: "No liked quotes have been chosen, go explore!", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
} else {
//segue to the other view
}
}
Also check your array count , that is why your wrong condition is executing 同时检查您的数组计数 ,这就是执行错误条件的原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.