2017-04-12 84 views
0
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中的按鈕圖像。當我點擊按鈕時,它會在圖像上顯示廣播,當我點擊下一個單元格時,按鈕圖像顯示單選按鈕,當按鈕處於正常狀態時,它會顯示廣播關閉按鈕。tableviewcell中的按鈕圖像不顯示任何變化

回答

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) 

    } 

}