我正在尝试禁用菜单按钮,数组显示为空。
这是我的代码。
@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
}
}
在ViewDidLoad()
中likedMenuButton.userInteractionEnabled = false
我已设法禁用该按钮,但我想发送一条消息,提醒用户该按钮被禁用的原因,否则,它有点令人困惑。
我将如何做到这一点?
感谢。
答案 0 :(得分:0)
默认情况下,用户交互为真,您无需将其设为真
@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
}
}
同时检查数组计数,这就是您执行错误条件的原因