【发布时间】:2025-12-23 22:05:11
【问题描述】:
我已经实现了一个 UICollectionView,它包含 UIImageView 对象的列表。
我希望用户在触摸图片时被带到具有特定 URL 的 YouTube。
但我不知道如何为每个 UICollectionViewCell 添加触摸监听器:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell: PhotoCell = collectionView.dequeueReusableCellWithReuseIdentifier("PhotoCell", forIndexPath: indexPath) as PhotoCell
cell.loadImage(thumbnailFileURLs[indexPath.row], originalImagePath: originalFileURLs[indexPath.row])
return cell
}
我的 PhotoCell 类有一个成员变量保存 youtube 的 URL。
对于每个 PhotoCell 对象,当按下时,我希望我的应用将用户发送到 youtube.com 网站或 APP(如果已安装)
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell