如何将UIImageView更改为自定义单元格 [英] How to change an UIImageView into a custom cell

查看:70
本文介绍了如何将UIImageView更改为自定义单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an UIImageView in a custom cell (@IBOutlet var imageSquadra: UIImageView!) and in the TableViewController I initialize this imageView:

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

        cell.imageSquadra.image = squadra.sfondo1

现在,我需要用其他图像来更改单元格中向上触摸的图像,并返回上一个向上触摸的图像进入另一个单元格。
很难吗?

Now I need to change the image touching up inside the cell with an other image, and return to the previous image touching up into an other cell. Is it hard to do?

编辑:或者,如果更简单,可以在图像上应用阴影等CAFilter。

or if was easier, would be fine apply a CAFilter like a shadow to the image.

推荐答案

在您的表视图上,将多个选择设置为NO:

On your tableview set multiple selection to NO:

tableView.allowsMultipleSelection = false

然后在TableViewController上想要这样的东西

Then you want something like this on your 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方法中,您想要类似...

In your cellForRow method you want something like...

cell.useSelectedImage(indexPath == storedIndexPath)

最后在您的自定义单元格类中哟您想添加一个与此功能相似的方法

And finally in your custom cell class you want to add a method that does similar to this

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

我的Swift有点生锈...但您应该可以从我在这里所做的事情中获得大致的认识

My Swift is a bit rusty... but you should be able to get the general idea from what I've done here

这篇关于如何将UIImageView更改为自定义单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆