首页 > 解决方案 > 如果在iOS中按下按钮,如何禁用它?

问题描述

我一直在查看此处的其他教程,以了解如何使按钮无法按下。但是,我不断收到此错误:

'(UIButton) -> ()' 类型的值没有成员 'isEnabled'

代码是:

@IBAction func PlayButton(_ sender: UIButton) {
    PlayButton.isEnabled = false
}

标签: iosswiftbuttondisable

解决方案


你这样做:

sender.isEnabled = false

另请注意,您的@IBAction函数与按钮具有相同的名称。这会导致名称歧义。将函数的名称更改为其他名称。


推荐阅读