我有一个水平滚动集合视图.
我正在寻找用向上或向下滑动手势删除项目的简洁方法.
重新排列元素也会令人惊讶,但此刻删除更为重要.
我找到了一些Obj-C文档,但是,由于我还是快速的Obj-C新手,对我来说太过分了.
在过去的几天里,我一直在处理同样的情况.这就是我用swift做的事情.我检查了迈克尔的链接并做了一些研究......
所以..
加上这个
let cSelector = Selector("reset:")
let UpSwipe = UISwipeGestureRecognizer(target: self, action: cSelector )
UpSwipe.direction = UISwipeGestureRecognizerDirection.Up
cell.addGestureRecognizer(UpSwipe)
Run Code Online (Sandbox Code Playgroud)
至
func collectionView(collectionView:UICollectionView,cellForItemAtIndexPath indexPath:NSIndexPath) - > UICollectionViewCell {
然后定义您的选择器,它实际上从您的数组中删除滑动项目,然后重新加载您的集合视图.
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.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6837 次 |
| 最近记录: |