Ruben Martinez Jr.
Ruben Martinez Jr.

Reputation: 3110

UIButton disabled in IBAction re-enables itself

I have a UIButton that is linked to an IBAction in a UIView. Within this IBAction, I both change the text of the UIButton's titleLabel and disable the UIButton. However, I've found that when the action fires, the button disables itself and changes its text for a split second before re-enabling itself. It's almost like it's happening just while the button is pressed, then it undoes itself. Could someone help with this? If it's useful, I'm on the latest Xcode and 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..."
}

Upvotes: 0

Views: 190

Answers (1)

Levi
Levi

Reputation: 7343

The text of the button should not be set like that. I am not very familiar with swift, but the right method should look something like:

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

And also make sure that the method is called on the touchUpInside action.

Upvotes: 0

Related Questions