1

I am building a tableview where I'm loading text of different sizes and want the cells to be dynamic. This is very simple when I'm not calling to the database first. I know I am using the constraints correctly because I got the cell to behave correctly when I wasn't calling to the database and just created an array. The only way I could get this to work was to call my function in viewDidLoad() to get the data, then in the closure reload the tableview. Then in vewDidAppear, I reload the tableView again. This works but seems ugly from a user experience side because the text loads once, and then resizes. Is there another way that I am unaware of? Thank you in advance!

Here is my viewDidLoad() and viewDidAppear() everything else in this controller is pretty basic.

override func viewDidLoad() {
    super.viewDidLoad()
    setupNavigationBarItems()
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
    commentTextView.delegate = self
    formatter.timeZone = TimeZone.current
    formatter.dateFormat = "yyyy-MM-dd HH:mm"

    tableView.estimatedRowHeight = 100
    tableView.rowHeight = UITableView.automaticDimension
    
    
    comment.getComments(roundID: roundID) {
        self.tableView.reloadData()
    }
    
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(true)
    self.tableView.reloadData()
}
Zack Blauvelt
  • 29
  • 1
  • 6

0 Answers0