Подтвердить что ты не робот

Отсутствие свойства редактирования и setEditing: анимированный: в UICollectionViewCell

Вряд ли UITableViewCell, UICollectionViewCell не имеет свойств setEditing:animated: и editing.

Это по дизайну? Является ли Apple лучшей практикой для обработки редактирования в UICollectionView и его ячейках?

4b9b3361

Ответ 1

Возможно, это то, что вам нужно:

Подкласс UICollectionViewController как ABCCollectionViewController:

let vc = UINavigationController(rootViewController: ABCCollectionViewController())

Тогда в viewDidLoad of 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)

Ответ 2

Если вы изменяете некоторое состояние типа 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
}