Ios 如何从表视图DidSelectRow方法内部将图像设置为UIButton?

Ios 如何从表视图DidSelectRow方法内部将图像设置为UIButton?,ios,swift,Ios,Swift,我在UITableView单元格中有一个UIButton。当用户点击任何单元格时,我想改变按钮的图像,我想改变didSelectRow方法。 在这里,我尝试了这个,但什么也没做: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tblDelivery.dequeueReusableCell(withIdentifier: "DeliveryTy

我在UITableView单元格中有一个UIButton。当用户点击任何单元格时,我想改变按钮的图像,我想改变didSelectRow方法。

在这里,我尝试了这个,但什么也没做:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let cell = tblDelivery.dequeueReusableCell(withIdentifier: "DeliveryTypeCell") as! DeliveryTypeCell
        cell.btnRadioSelect.setImage(UIImage(named: "radioButtonChecked"), for: .normal)
}

问题可能是您正在调用dequeueReusableCellWithIdentifier。尝试改用CellForRowatineXpath。这将提供对当前单元格的引用,而不是对新的可重用单元格的引用

因此,根据您上面的代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
    let cell = tblDelivery.cellForRow(at: indexPath) as! DeliveryTypeCell
    
    cell.btnRadioSelect.setImage(UIImage(named: "radioButtonChecked"), for: .normal)
}

你能展示一下你试过的吗?你有什么具体问题?