Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 更改表格视图单元格中的图像按钮_Swift_Uitableview_Button_Cell - Fatal编程技术网

Swift 更改表格视图单元格中的图像按钮

Swift 更改表格视图单元格中的图像按钮,swift,uitableview,button,cell,Swift,Uitableview,Button,Cell,我有两个类TableViewController和CustomCell,然后将IB中的按钮(likeBtn)连接到CustomCell 现在,我想改变这个按钮的图像 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cellIdentifier = "Cell" let cell = tableView.d

我有两个类
TableViewController
CustomCell
,然后将
IB
中的按钮(
likeBtn
)连接到
CustomCell

现在,我想改变这个按钮的图像

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "Cell"

        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! CustomCell

        // Configure the cell...            
        cell.likeBtn.addTarget(self, action: #selector(TableViewController.liked), for: .touchUpInside)

        return cell
    }

@objc func liked(sender: UIButton) {

        cell.likeBtn.setImage(UIImage(named: "liked.png"), for: .normal)
        cell.likeBtn.isUserInteractionEnabled = false
    }
但是在
liked()
中,我有关于
cell.likeBtn
的错误


我正在使用swift 4编程,正确的方法应该是:

@objc func liked(sender: UIButton) {
    sender.setImage(UIImage(named: "liked.png"), for: .normal)
    sender.isUserInteractionEnabled = false
}

您好,谢谢,我想到了
sender.tag
或pass参数,lol。现在我遇到了一个错误,当单击第一个单元格时,表中的一些单元格被单击!!如果您只想单击某些单元格按钮,只需在cellForRowAt中执行此操作:If indexath.row==(哪一行){cell.likeBtn.addTarget(self,action:#selector(TableViewController.like),for:.touchUpInside)}thx,但我想单击表中的任何单元格,并将其保存为我单击过的单元格!您可以始终添加标记,您的标记可以是indexath.row,这样每个按钮都有一个唯一的标记