Edit: this is different from the duplicate because I have two variable-height labels, not one
I'm trying to do what I thought would be very simple. I have a table cell that has two labels in it. Each of those labels is loaded in via a dynamic data source and they could be of any length. I need the the labels to grow and shrink according to the data that's inside of them. This is turning out to be quite a challenge.
I have created a new project that is absolutely bare boned in hopes of getting to the root of the problem.
Both of my labels are set to 0 lines and line breaks: Word Wrap
Any help is great appreciated.
And the code that I currently have:
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self.tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
}
- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
Solution found:
I added the following line of code before returning the cell, and everything magically worked.
[cell updateConstraintsIfNeeded];