gpt4 book ai didi

swift - 表格 View 单元格中的更改图像按钮

转载 作者:行者123 更新时间:2023-11-28 15:14:17 24 4
gpt4 key购买 nike

我有两个类 TableViewControllerCustomCell 然后将 IB 中的按钮(likeBtn)连接到 自定义单元格

现在,我想更改此按钮的图像!

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
}

关于swift - 表格 View 单元格中的更改图像按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47152718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com