如何禁用 UIButton 并发送 UIAlertView 消息

How to disable a UIButton and send a UIAlertView message

我正在尝试禁用菜单按钮,但数组显示为空。

这是我的代码。

@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

我已经设法禁用该按钮,但我想发送一条消息提醒用户为什么该按钮被禁用,否则会有点混乱。

我该怎么做?

谢谢。

默认情况下,用户交互为真,您无需使其为真

@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