我有一个填充的collectionView,它包含所有这些按钮的隐藏删除按钮,只有在用户按下并按住单元格后才会出现。我试图这样做,以便当他们按住一个单元格时,只有他们按下的单元格才会启用并显示删除按钮。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! homeworkcell
id = indexPath.item
cell.delteButton.hidden = true
cell.delteButton.enabled = false
// remove swipe gestures
if cell.gestureRecognizers?.count != nil {
for recognizer in cell.gestureRecognizers! {
cell.removeGestureRecognizer(recognizer)
}
}
// add the swipe gestures
let longPress = UILongPressGestureRecognizer(target: self, action: "deleteMode:")
cell.addGestureRecognizer(longPress)
cell.tag = indexPath.row
... return cell
}
func deleteMode(sender: UISwipeGestureRecognizer) {
let indexPath = NSIndexPath(forRow: sender.view!.tag, inSection: 0)
if let cell = collectionView.cellForItemAtIndexPath(indexPath) as! homeworkcell! {
cell.delteButton.hidden = false
cell.delteButton.enabled = true
}
//userDelete = true
userWantsToRemoveDeleteButton = false
doneEditingButton.enabled = true
collectionView.reloadData()
}
然而,当我运行程序时,删除按钮永远不会显示,这必然意味着我正在错误地获取所选单元格的indexPath,我声明了单元格错误,或者其他我不知道的东西。是否有一些代码我缺少指定按钮出现的单元格?
任何帮助将不胜感激。 (同样,deleteButton拼错为delteButton,抱歉)。