Change button image on selection in custom table view cell

时间:2015-06-30 19:21:23

标签: swift

I am beginner to Swift. I tried many tutorials but not helpful. I want to change button image of specific custom cell on selection.

2 个答案:

答案 0 :(得分:1)

我的朋友非常简单

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
 var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
  //you got your cell now suppose your button tag is 3 
 var button:UIButton = cell.contentView.viewWithTag(3) as! UIButton
 //you got you button now change the image of the button its done
}

答案 1 :(得分:0)

swift 3.0 //显示箭头符号

cell2.accessoryType = .disclosureIndicator

//更改按钮图像

    cell2.CheckBtn.setBackgroundImage(UIImage (named: "image name like "Govind""), for: UIControlState.normal)

其工作