繁体   English   中英

如何禁用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

我已经设法禁用了该按钮,但是我想发送一条消息,警告用户为什么该按钮被禁用,否则,会有些混乱。

我将如何去做呢?

谢谢。

默认情况下,用户交互为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
        }
    }

同时检查您的数组计数 ,这就是执行错误条件的原因

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM