Can you animate a height change on a UITableViewCell when selected?

前端 未结 21 1027
天涯浪人
天涯浪人 2020-11-22 04:41

I\'m using a UITableView in my iPhone app, and I have a list of people that belong to a group. I would like it so that when the user clicks on a particular pers

21条回答
  •  [愿得一人]
    2020-11-22 04:48

    Swift Version of Simon Lee's answer .

    // MARK: - Variables 
      var isCcBccSelected = false // To toggle Bcc.
    
    
    
        // MARK: UITableViewDelegate
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    
        // Hide the Bcc Text Field , until CC gets focused in didSelectRowAtIndexPath()
        if self.cellTypes[indexPath.row] == CellType.Bcc {
            if (isCcBccSelected) {
                return 44
            } else {
                return 0
            }
        }
    
        return 44.0
    }
    

    Then in didSelectRowAtIndexPath()

      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
    
        // To Get the Focus of CC, so that we can expand Bcc
        if self.cellTypes[indexPath.row] == CellType.Cc {
    
            if let cell = tableView.cellForRowAtIndexPath(indexPath) as? RecipientTableViewCell {
    
                if cell.tag == 1 {
                    cell.recipientTypeLabel.text = "Cc:"
                    cell.recipientTextField.userInteractionEnabled = true
                    cell.recipientTextField.becomeFirstResponder()
    
                    isCcBccSelected = true
    
                    tableView.beginUpdates()
                    tableView.endUpdates()
                }
            }
        }
    }
    

提交回复
热议问题