【问题标题】:UIButton disabled in IBAction re-enables itself在 IBAction 中禁用的 UIButton 重新启用自身
【发布时间】:2014-10-16 20:57:46
【问题描述】:

我有一个 UIButton,它链接到 UIView 中的 IBAction。在此 IBAction 中,我更改了 UIButton 的 titleLabel 的文本并禁用了 UIButton。但是,我发现当动作触发时,按钮会在重新启用之前禁用自身并在瞬间更改其文本。这几乎就像它在按下按钮时发生,然后它会自行撤消。有人可以帮忙吗?如果有用的话,我正在使用最新的 Xcode 和 iOS 8 SDK。

//this is the IBAction...it happens, but the enabled property and text change quickly undoes itself.
@IBAction func solvePuzzle(sender: AnyObject) {
    self.activity.startAnimating()
    self.solveButton.enabled = false
    self.solveButton.titleLabel?.text = "Solving..."
}

【问题讨论】:

    标签: ios swift uibutton


    【解决方案1】:

    按钮的文本不应该这样设置。我对 swift 不是很熟悉,但是正确的方法应该是这样的:

    self.solveButton.setTitle("Solving...", forState:UIControlState.Normal);
    

    还要确保在 touchUpInside 操作上调用该方法。

    【讨论】:

    • 你是对的!这确实使改变坚持下去!我很困惑为什么另一种方法有效但自己解开了,但这似乎已经成功了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多