【发布时间】:2018-02-04 19:23:12
【问题描述】:
我想向我的CollectionViewCell 添加一个点击事件,并将我的cell 与它拥有的数据一起传递到那里。我怎样才能做到这一点?
这个事件应该由我的ViewController 处理还是由CollectionViewCell 处理?
我的ViewController:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
cell.imgImage.image = imageArray[indexPath.row]
cell.url = "xhini"
return cell
}
我的CollectionViewCell:
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imgImage: UIImageView!
var url: String = "url"
}
【问题讨论】:
标签: ios swift uicollectionview