[英]Custom button image in tableview cell isnt changing?
Ive got a custom tableview with a label and button. 我有一个带标签和按钮的自定义tableview。 When the button is pressed on an individual cell, the image should change.
按下单个单元格上的按钮时,图像应该更改。 But it doesnt?
但它不是吗?
so it logs "testing" when I click the individual custom tableview cell button, but the image doesnt change. 因此,当我单击单个自定义tableview单元格按钮时,它会记录“测试”,但图像不会更改。
@IBAction func tickAction(sender: UIButton) {
println("testing")
if let image = UIImage(named:"Unchecked.png") {
sender.setImage(UIImage(named:"Checked.png"), forState: .Normal)
}
if let image = UIImage(named:"Checked") {
sender.setImage(UIImage(named:"Unchecked.png"), forState: .Normal)
}
}
Your condition is wrong. 你的病情有误。 Which image you are checking?
你正在检查哪个图像?
try to do it like: 尝试这样做:
@IBAction func tickAction(sender: UIButton) {
println("testing")
if (sender.selected) {
sender.setImage(UIImage(named:"Unchecked.png"), forState: .Normal)
sender.selected = false
}
else {
sender.setImage(UIImage(named:"Checked.png"), forState: .Normal)
sender.selected = true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.