gpt4 book ai didi

ios - 如何禁用 UIButton 并发送 UIAlertView 消息

转载 作者:行者123 更新时间:2023-11-30 13:40:41 27 4
gpt4 key购买 nike

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

这是我的代码。

@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
}
}

Also check your array count, that is why your wrong condition is executing

关于ios - 如何禁用 UIButton 并发送 UIAlertView 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35594446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com