gpt4 book ai didi

swift - 点击单元格并获取索引

转载 作者:行者123 更新时间:2023-11-28 13:02:15 25 4
gpt4 key购买 nike

当我点击一个单元格时,我想接收索引或其他特定于该单元格的标识符。该代码可以正常工作并进入 tapped 功能。但是我怎样才能收到索引或类似的东西呢?

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ShowCell", forIndexPath: indexPath) as UICollectionViewCell

if cell.gestureRecognizers?.count == nil {
let tap = UITapGestureRecognizer(target: self, action: "tapped:")
tap.allowedPressTypes = [NSNumber(integer: UIPressType.Select.rawValue)]
cell.addGestureRecognizer(tap)
}

return cell
}

func tapped(sender: UITapGestureRecognizer) {
print("tap")
}

最佳答案

Swift 4 - 4.2 - 返回点击单元格的索引。

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cellIndex = indexPath[1] // try without [1] returns a list.
print(indexPath[1])
chapterIndexDelegate.didTapChapterSelection(chapterIndex: test)
}

关于swift - 点击单元格并获取索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33616212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com