Swift CollectionView使用滑动手势删除项目

Swift CollectionView使用滑动手势删除项目,swift,swipe,Swift,Swipe,我有一个水平滚动的集合视图 func reset(sender: UISwipeGestureRecognizer) { let cell = sender.view as! UICollectionViewCell let i = self.favoritesCV.indexPathForCell(cell)!.item favoritesInstance.favoritesArray.removeAtIndex(i) //replac

我有一个水平滚动的集合视图

    func reset(sender: UISwipeGestureRecognizer) {
        let cell = sender.view as! UICollectionViewCell
        let i = self.favoritesCV.indexPathForCell(cell)!.item
        favoritesInstance.favoritesArray.removeAtIndex(i)  //replace favoritesInstance.favoritesArray with your own array
        self.favoritesCV.reloadData() // replace favoritesCV with your own collection view.
    }
我正在寻找一种向上或向下滑动的方式来移除物品。
此外,重新安排元素将是令人惊讶的,但目前移除更为重要


我发现了一些Obj-C文档,但由于我还是swift Obj-C的新手,这对我来说太多了。

过去几天我一直在处理相同的情况。 这是我对斯威夫特所做的。。我查了Michael的链接,也做了一些调查

所以

加上这个

    let cSelector = Selector("reset:")
    let UpSwipe = UISwipeGestureRecognizer(target: self, action: cSelector )
    UpSwipe.direction = UISwipeGestureRecognizerDirection.Up
    cell.addGestureRecognizer(UpSwipe)

func collectionView(collectionView:UICollectionView,cellForItemAtIndexPath indexath:NSIndexPath)->UICollectionView单元格{

然后定义选择器,它实际上会从数组中删除已扫描的项目,然后重新加载集合视图

    func reset(sender: UISwipeGestureRecognizer) {
        let cell = sender.view as! UICollectionViewCell
        let i = self.favoritesCV.indexPathForCell(cell)!.item
        favoritesInstance.favoritesArray.removeAtIndex(i)  //replace favoritesInstance.favoritesArray with your own array
        self.favoritesCV.reloadData() // replace favoritesCV with your own collection view.
    }

到目前为止,你离目标有多近?你能抓住一个项目并移动它吗,即使更改没有保存?有Objective-C的答案,但你应该能够很容易地为列出的几个API找到Swift等价物…非常感谢..我实际上做了类似的事情,但你的解决方案更整洁。你也可以将手势识别器子类化然后通过考试