I have a tableview that is getting populated with data from Firebase. However, when resizing the tableview using automatic dimension, some text is shown getting cut off.
Here is my Storyboard with constraints set to top, bottom, right, and left.
It is working fine when there is not alot of text as shown here.
However, when I fill the cell with alot of text this occurs.
Here is the code that I am currently using.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (tableView == questInformationTableView) {
return 50
}
else if (tableView == questWalkthroughTableView) {
return UITableView.automaticDimension
}
return 0
}
override func viewDidLoad() {
super.viewDidLoad()
questWalkthroughTableView.estimatedRowHeight = 250
questWalkthroughTableView.rowHeight = UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
I have also set numberOfLines to 0 and set the label to .sizeToFit()
A UITableView instance calls these two methods to request the information it needs, piece by piece. The methods of a data source can be called more than once. A UITableView instance does not store any data.
While a table view offers many sophisticated features, The UITableViewDataSource protocol has only two required methods. Implementing these two is enough to have a working table view. A UITableView instance calls these two methods to request the information it needs, piece by piece.
For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views. The code of the table view data source often ends inside view controllers when it should go into a separate class.
QuoteCell The critical line of code in this method is the call to the dequeueReusableCell(withIdentifier:) methods of UITableView. This returns a cell we can reuse, or creates a new one when none is available. The QuoteCell class already handles data formatting, so all we need to do here is pass the quote data to the cell instance.
Don't make the bottom constraint greater than or equal to just set it like the top constraint. Take away the estimatedHeightForRowAt
and heightForRowAt
functions. Your view did load declarations are sufficient. When you reload data also call self.view.layoutIfNeeded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With