ios - 在 didSelectRowAtIndexPath 中更改自定义 UIImage

标签 ios swift uitableview

我的单元格中有一个自定义的 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/

相关文章:

ios - 通过 hyperoslo 检索表单中的选择字段

ios - Sprite Kit 艺术 Assets 命名约定

arrays - 数组仅包含最后添加的值但计数仍然相同

swift - 不要用 Xcode 8 复制 swift 库?

ios - iOS中如何完成Segmented Control的文本显示?

ios - 为什么 UISearchBar tableview 索引路径总是返回 objectAtIndex :0

ios - 我如何获取数据并在 viewdidload 中使用它......而不是在函数内部?

ios - 更新 UITableView 单元格和 SwiftyPickerPopover 时出现问题

ios - 如何在 tableViewCell 中运行 imagePicker

ios - 在 UITableViewController 的 UINavigationItem 栏中从 "Done"更改后按下 "Edit"时触发什么?