tableviewcell中的按钮图像不显示任何更改

时间:2017-04-12 04:57:23

标签: swift3 uibutton

import UIKit

``class SelectOptionsTableViewCell: UITableViewCell {

@IBOutlet weak var Radiobutton: UIButton!


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    Radiobutton.setImage(UIImage.init(named: "Radio OFF.jpg"), for: .normal)
    Radiobutton.setImage(UIImage.init(named: "Radio ON.jpg"), for: .selected)

}


@IBAction func RadioButton(_ sender: Any) {
    print("buttonClicked")
   // Radiobutton.setImage(UIImage.init(named: "Radio ON.jpg"), for: .selected)

}
override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

我正在尝试更改tableviewcell中的按钮图像。当我单击按钮时,它会在图像上显示无线电,当我单击下一个单元格时,按钮图像会显示单选按钮,当按钮处于正常状态时,它会显示无线电关闭按钮。

1 个答案:

答案 0 :(得分:0)

您必须在按钮单击

上编写设置图像的代码
@IBAction func RadioButton(_ sender: Any) { 

sender.isSelected = !sender.isSelected

if sender.isSelected 
{

 Radiobutton.setImage(UIImage.init(named: "Radio ON.jpg"), for: .selected)
}

else
{

  Radiobutton.setImage(UIImage.init(named: "Radio OFF.jpg"), for: .normal)

  }

}