How to update each custom tableview cell data at the same time?

后端 未结 4 1244
长发绾君心
长发绾君心 2020-12-14 10:09

I am using Xcode 8.2.1 with Swift 3. I have one custom UITableViewCell containing a UITextView. When I type into the textView, the custom cell automatically gro

4条回答
  •  温柔的废话
    2020-12-14 10:59

    every time you need update cell use this code:

    func updateCellHeight(indexPath: IndexPath, comment: String) {
    
      //update dataModel according to new text
      ...
      //then reload visible tableview rows
      //pay atttention to beginUpdates endUpdates methods.
      //This do the trick)
    
      tableView.beginUpdates()
      tableView.reloadRows(at: indexPathsForVisibleRows ?? [], with: .none)
      tableView.endUpdates()
    
     }
    

提交回复
热议问题