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

后端 未结 4 1245
长发绾君心
长发绾君心 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:46

    Firstly, from storyboard or in your tableView Cell class set the textviews NumberOfLines = 0 .

    In the height for row delegate have

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    

    In your viewdidLoad add these lines:

    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 140
    

    In the tableViewController

     func updateCellHeight(indexPath: IndexPath, comment: String) {
    
        let currentCellLyricVal = self.traduzioneArray[indexPath.row]["rics"]
        tempIndexArray.removeAll()
    
        for (index,element) in traduzioneArray.enumerated() {
    
            let lyricVal = element["rics"]
            if currentCellLyricVal == lyricVal {
                tempIndexArray.append(index)
            }
        }
        for index in tempIndexArray {
            self.traduzioneArray[index]["ione"] = comment
        }
          tableView.reloadRows(at: [IndexPath(row: 11, section: 1),IndexPath(row: 13, section: 1)], with: UITableViewRowAnimation.none)
    }
    

    By having the lines set to 0 and auto dimension height the cells automatically resize. Please also verify that you set your custom cells delegate to self in yourcellForRowmethod.

提交回复
热议问题