【问题标题】:How to change an UIImageView into a custom cell如何将 UIImageView 更改为自定义单元格
【发布时间】:2015-11-29 08:39:33
【问题描述】:

我在自定义单元格 (@IBOutlet var imageSquadra: UIImageView!) 中有一个 UIImageView,在 TableViewController 中我初始化了这个 imageView:

let squadra = DataManager.sharedInstance.arrayCori[indexPath.row]

        cell.imageSquadra.image = squadra.sfondo1

现在我需要将单元格内部的图像更改为另一个图像,然后返回到之前的图像接触另一个单元格。 很难做到吗?

编辑:或者如果更简单,可以将 CAFilter 像阴影一样应用于图像。

【问题讨论】:

    标签: swift uiimageview uiimage cell


    【解决方案1】:

    在您的 tableview 上将多项选择设置为 NO:

    tableView.allowsMultipleSelection = false
    

    然后你想在你的 TableViewController 上做这样的事情

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
       // Store which indexPath has been selected in a global variable
    
       tableView.reloadData()
    }
    
    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.reloadData()
    }
    

    在您的 cellForRow 方法中,您需要类似...

    cell.useSelectedImage(indexPath == storedIndexPath)
    

    最后,在您的自定义单元类中,您要添加一个与此类似的方法

    func useSelectedImage(bool:useSelected)
    {
         self.myImage = useSelected ? "selectedImage" : "unselectedImage"
    }
    

    我的 Swift 有点生疏了……但你应该能够从我在这里所做的事情中得到大致的想法

    【讨论】:

      猜你喜欢
      • 2015-12-25
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多