11

不太可能 UITableViewCell、UICollectionViewCell 缺少setEditing:animated:editing属性。

这是设计使然吗?Apple 是否强制执行其他最佳实践来处理 UICollectionView 及其单元格中的编辑?

4

2 回答 2

-1

也许这就是你需要的:

子类 UICollectionViewController 像ABCCollectionViewController

let vc = UINavigationController(rootViewController: ABCCollectionViewController())

然后viewDidLoadABCCollectionViewController

self.navigationItem.leftBarButtonItem = self.editButtonItem

然后重写 setEditting 方法:

override func setEditing(_ editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: true)

    // Use these methods to do the edit things, without test but should works
    collectionView?.beginInteractiveMovementForItem(at: indexPath)
    print("editting")//Do some edit thing
    collectionView?.endInteractiveMovement()  
    collectionView.updateInteractiveMovementTargetPosition()
    collectionView?.cancelInteractiveMovement()
}

然后你可以调用:

setEditing(true, animated: true)
于 2017-11-09T09:01:03.610 回答
-1

allowsMultipleSelection如果您在编辑时更改某些状态UICollectionView

override func setEditing(_ editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)
    collectionView.allowsMultipleSelection = editing
}

您可以简单地将其添加到您的UICollectionViewCell子类中:

var isEditing: Bool {
    return (superview as! UICollectionView).allowsMultipleSelection
}
于 2017-12-09T06:40:42.267 回答