I'm doing with Xcode 10. I have a tableview in ViewController.
The cell has label which is set as leading, tralling, top and bottom, line is 0
In ViewDidload() I added
override func viewDidLoad() {
super.viewDidLoad()
tableview.rowheight = UITableView.automaticDimension
tableview.estimateheight = 98
tableview.reloaddata()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CommentCell", for: indexPath) as! CommentCell
let idcmt: String
idcmt = self.CommentIDArray[indexPath.row]
ref.child("Post_theme/\(userid!)/\(id)/comment/\(idcmt)").observe( .value, with: {(snapshot) in
let value = snapshot.value as? NSDictionary
cell.Comment.text = value!["content"] as? String
})
// I have a button in the custom cell but tableview load height wrong even I did not click the button on cell
self.ref.child("Post_theme/\(self.userid!)/\(self.id)/comment/\(idcmt)/likecomment").observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.hasChild(self.userid!){
cell.Heartcommentaction = {
cell.HeartCommentbutton.tintColor = .lightGray
self.TableCommentView.reloadData()
}
}
})
return cell
}
class CommentCell: UITableViewCell{
var Heartcommentaction : (() -> ()) = {}
@IBOutlet weak var Comment: UILabel!
@IBOutlet weak var HeartCommentbutton: UIButton!
@IBAction func HeartCommentaction(_ sender: Any) {
Heartcommentaction()
}
}
But when I click to Viewcontroller, tableview did not load the right height cell ( cell which is needed to autorize is not, cell which is not needed is resize)
Then I add this code
override func viewDidAppear(_ animated: Bool) {
tableview.reloadData()
}
the code run well just for initial few cells, but when I scroll down more (I have around over 100 cells), it's wrong height again, when I scroll up the initial cells get again wrong
I looked many solutions but not working for me
Really need help! thank you
UPDATE
this is the screenshot of wrong height cell, some timewrong, sometime right