我试图在选中它时更改单元格内的图像。以下是我在我的视图控制器:在桌面单元格内选择更改图像 - Swift
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell
cell.bgImage.image = UIImage(named: "second_image")
}
这是我设置的图像:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell
cell.bgImage.image = UIImage(named: "first_image")
}
当我选择单元格,图像不更新。我如何得到这个工作?
谢谢!但这不会更新图像:( –
对不起,这给出了一个错误,说该单元没有名为bgImage –
的成员而且你的imageView被称为bgImage?你可以发布你的代码添加imageView到单元格的位置 –