【发布时间】:2013-07-23 15:33:13
【问题描述】:
不太可能是 UITableViewCell,UICollectionViewCell 缺少 setEditing:animated: 和 editing 属性。
这是设计使然吗? Apple 是否强制执行其他最佳实践来处理 UICollectionView 及其单元格中的编辑?
【问题讨论】:
标签: ios uitableview uicollectionview uicollectionviewcell
不太可能是 UITableViewCell,UICollectionViewCell 缺少 setEditing:animated: 和 editing 属性。
这是设计使然吗? Apple 是否强制执行其他最佳实践来处理 UICollectionView 及其单元格中的编辑?
【问题讨论】:
标签: ios uitableview uicollectionview uicollectionviewcell
如果您在编辑时更改UICollectionView 中的allowsMultipleSelection 之类的状态:
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
collectionView.allowsMultipleSelection = editing
}
您可以简单地将其添加到您的 UICollectionViewCell 子类中:
var isEditing: Bool {
return (superview as! UICollectionView).allowsMultipleSelection
}
【讨论】:
也许这就是你需要的:
子类 UICollectionViewController 如ABCCollectionViewController:
let vc = UINavigationController(rootViewController: ABCCollectionViewController())
然后在viewDidLoad 的ABCCollectionViewController 中:
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)
【讨论】: