我的单元格中有一个自定义的 UIImage
,我需要在调用 didSelectRowAtIndexPath
时更改它。由于某种原因,图像没有改变,我认为这是因为我在方法中声明了单元格。
class CustomCell: UITableViewCell {
@IBOutlet weak var indicator: UIImageView!
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as! CustomCell
cell.indicator.image = UIImage(named: "newImage")
}
如何在单击单元格时将我的 UIImage
更改为“newImage”?
最佳答案
从索引路径创建单元格
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomCell
cell.indicator.image = UIImage(named: "newImage")
}
关于ios - 在 didSelectRowAtIndexPath 中更改自定义 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31236775/