Reputation: 1221
I have a UITableViewCell that contains three buttons, I want to make these buttons as not enabled, but I also want to choose dynamically which one of them is selected.
I did that but my problem is that when I make the button as not enabled, the text doesnt' show
look this is what it looks like when the button is not enabled
this is what it looks like when the button is enabled (this is the correct way, but in this case i can click on the buttons, which I dont want)
this is my code
for (index, button) in [cell.firstTimeOption, cell.secondTimeOption, cell.thirdTimeOption].enumerate() {
if oneResponse.timeOptions.count > index {
button.setTitle(oneResponse.timeOptions[index], forState: .Selected)
button.setTitle(oneResponse.timeOptions[index], forState: .Normal)
button.enabled = false
if index == oneResponse.selectedOptionIndex {
button.selected = true
}else {
button.selected = false
}
button.hidden = false
} else {
button.hidden = true
}
}
Upvotes: 0
Views: 38
Reputation: 7210
I may be mistaken as to how you want your button to behave, but from what I took of what you want shouldn't you not be using:
button.hidden = true;
As this will remove the button from the view entirely, which sure disables it, but it also makes it disapear!
I believe you want:
button.userInteractionEnabled = true;
Or
button.userInteractionEnabled = false;
Accordingly.
Upvotes: 2