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

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

    Once you update the data set with the new data. Reload the particular cells with the updated data set.

    func updateCellHeight(indexPath: IndexPath, comment: String) {
            DispatchQueue.main.async {
                let currentCellLyricVal = self.traduzioneArray[indexPath.row]["rics"]
                tempIndexArray.removeAll()
    
                for (index,element) in traduzioneArray.enumerated() {
    
                    let lyricVal = element["rics"]
                    //You have to skip the current cell. by checking index != indexPath.row
                    if currentCellLyricVal == lyricVal, index != indexPath.row {
                        tempIndexArray.append(index)
                    }
                }
    
                for index in tempIndexArray {
                    self.traduzioneArray[index]["ione"] = comment
    
                    let updatedIndexPath = IndexPath(row: index, section: indexPath.section)
                      if let visibleCellIndexPaths = tableView.indexPathsForVisibleRows  {
                           if visibleCellIndexPaths.contains(updatedIndexPath) {
                                tableView.reloadRows(at: [updatedIndexPath], with: .automatic)
                           }
                      }
                }
            }
        }
    

    NOTE: If the modified data set cells are visible then only we have to reload the particular cells.

提交回复
热议问题