【问题标题】:Lack of editing property and setEditing:animated: in UICollectionViewCellUICollectionViewCell 中缺少编辑属性和 setEditing:animated:
【发布时间】:2013-07-23 15:33:13
【问题描述】:

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

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

【问题讨论】:

    标签: ios uitableview uicollectionview uicollectionviewcell


    【解决方案1】:

    如果您在编辑时更改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
    }
    

    【讨论】:

      【解决方案2】:

      也许这就是你需要的:

      子类 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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-07
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 1970-01-01
        • 2020-03-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多