I am having trouble getting my comment cells to resize properly after a comment is posted.
When the Comment View first loads, everything looks good.
However, right after a comment is posted, the cells still retain their previous size and do not automatically resize.
This leads to new comment cells having the wrong dimensions (see pictures):
The comment view when it first loads. Comment cells are the correct size.
About to post a one line comment.
Oh no: The new comment is posted but the old cell sizes are used instead.
The AutoLayout constraints for the Comment Cell are done in the storyboard.
The numberOfLines attribute for the comment text view is set to 0.
In the CommentViewController, estimatedRowHeight and automaticDimension are used:
self.tableView.estimatedRowHeight = 77
self.tableView.rowHeight = UITableView.automaticDimension
Edit: layoutIfNeeded() is used as well.
In the CommentTableViewCell class, prepareForReuse is called:
override func prepareForReuse()
{
super.prepareForReuse()
}
After the new comment is posted, pulling to refresh does not readjust the cell size. The only way to fix it is to click the back button and re-enter the Comment View.
How do I fix this problem?
Thank you for your time.
Edit: Added screenshot of my storyboard, heirarchy and constraints
Edit: Updated constraints, made comment label purple for visibility
Top of display name label to top of content view.
Top of comment label to bottom of display name label.
Bottom of comment label to bottom of content view.
Added purple to the background to make it more clear what's going on.
After the comments are reloaded, the comment cell constraints fail to adjust to the comments properly. How do I fix this?
Thank you for your time.
Final Edits: Removed unnecessary code and posted my solution in the comments