我試圖在選中它時更改單元格內的圖像。以下是我在我的視圖控制器:在桌面單元格內選擇更改圖像 - 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到單元格的位置 –