gpt4 book ai didi

ios - UICollectionView 手势事件

转载 作者:行者123 更新时间:2023-11-29 01:18:18 24 4
gpt4 key购买 nike

我想在 UICollectionView 中长按单元格时显示删除按钮。当我单击单元格时,它会显示,当单击单元格外部时,它会出现异常 “ fatal error :在展开可选值时意外发现 nil” 如何解决?我的代码在下面给出

func handleLongPress(gestureReconizer: UILongPressGestureRecognizer) {


if gestureReconizer.state == UIGestureRecognizerState.Began
{
let p = gestureReconizer.locationInView( self.sectionImageCell._collectionView!)

let touchedIndexPath : NSIndexPath? = self.sectionImageCell._collectionView!.indexPathForItemAtPoint(p)!//Here getting exception when click on outside the cell in a uicollectionview

if touchedIndexPath != nil {


for item in sectionImageCell._collectionView!.visibleCells() as! [CollectionViewcell] {

let indexpath : NSIndexPath = self.sectionImageCell._collectionView!.indexPathForCell(item as CollectionViewcell)!
let cell : CollectionViewcell = self.sectionImageCell._collectionView!.cellForItemAtIndexPath(indexpath) as! CollectionViewcell


//Close Button


if touchedIndexPath == indexpath {
if cell._closeBtn.hidden == false {
cell._closeBtn.hidden = true
}
else {
cell._closeBtn.hidden = false
}
}
}
}

}

}

最佳答案

if let 展开 self.sectionImageCell._collectionView!.indexPathForItemAtPoint(p)! ,你的问题就解决了。

关于ios - UICollectionView 手势事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34896759/

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