【问题标题】:Remember state of cell after animation记住动画后的单元格状态
【发布时间】:2020-06-25 19:38:42
【问题描述】:

非常感谢以下任何建议。

我正在尝试让我的表格记住动画完成后的状态。下面是我的表格,当我按下“邀请”按钮时,动画会从单元格中删除按钮。但是在向下滚动和向后滚动时,reusableCell 会再次绘制按钮。

我决定使用数组来记住,哪些单元格是动画的,但不知道如何在单元格创建过程中不绘制单元格的某些元素(按钮)。

【问题讨论】:

    标签: swift uitableview cell


    【解决方案1】:

    试试这个: 创建一个名为 animationIsCalled 的布尔变量并将其设置为 false。

    var animationIsCalled = [Bool](repeating: false, count: numberOfTableViewCells)
    
    @IBAction func buttonPressed(sender: UIButton){
        if animationIsCalled{
            //Your code is here
        }
        animationIsCalled[indexPath.row] = false
    }
    

    我不知道你的方法是不是IBAction类型,但是如果是,你就不能使用indexPath.row。但是尝试使用这个布尔变量的想法,因为我以前使用过它,这是一个非常有用的策略。 希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      亚历克斯,非常感谢您的回答!经过一些实验,以下代码起作用了:

      //Create array to remember already animated cells
      var sectionTwoSent = [String]()
      
      //Once button tapped append user_id to array above
      self.sectionTwoSent.append(self.sectionTwo[indexPath.row].user_id)
      
      //During cell creation, make check and alpha = 0 to hide buttons
      for item in sectionTwoSent {
       if contact.user_id == item {
          cell.inviteButton?.alpha = 0
          cell.removeButton?.alpha = 0
          cell.invitationDoneLabel?.alpha = 1
          break
          } else {
             cell.inviteButton?.alpha = 1
             cell.removeButton?.alpha = 1
             cell.invitationDoneLabel?.alpha = 0
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多