【发布时间】:2015-09-08 13:55:33
【问题描述】:
在我的UICollectionView 的每个单元格中,我都有多个要与之交互的对象。
因此,我真的想在单元格的每个对象上添加一个点击手势,而不是使用didSelect 委托方法。
为简单起见,我删除了示例中的所有其他对象:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! PlacesCollectionViewCell
let tap = UITapGestureRecognizer(target: self, action: "gotToSelectedPlace:")
tap.numberOfTapsRequired = 1
cell.imageView.userInteractionEnabled = true
cell.imageView.addGestureRecognizer(tap)
cell.imageView.file = places[indexPath.row].picture
cell.imageView.loadInBackground()
return cell
}
在 viewDidLoad 中,我使用笔尖:
collectionView.registerNib(UINib(nibName: "PlacesCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "Cell")
UICollectionView 设置:
- 延迟内容触摸:是的
- 可取消的内容触摸:是的
在这个例子中,我无法处理点击手势。什么都没发生。 我错过了什么吗??
谢谢
【问题讨论】:
-
您遇到了问题。单元格已经有一个轻击手势。那只是选择它。你不能在 didSelectItemAtIndexPath 和 didDeselect 中处理你的交互吗?
-
imageView 是什么类型的对象?标准 UIImageView 没有
file属性或loadInBackground()方法。这可能是问题 -
我忘了说,这个是PFFile,UIImageView的子类...
-
@soulshined 我没有使用 didSelect 委托方法,所以在我看来没有问题。你不觉得吗?
标签: ios swift uicollectionview uitapgesturerecognizer