簡體   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