I want to know is it possible to have a standard UITableViewCell with style UITableViewCellStyleSubtitle having dynamic height?
If yes, then how to achieve that?
numberOfLines property of cell.textLabel and cell.detailTextLabel to 0.Alright, if your textLabel contains multiple line content and detailTextLabel contains single line content, then the tableView adjusts cell height automatically. But if it is other way round then it doesn't! Is this a bug by Apple? or expected functionality?
Below are the screen shots


The estimated height of rows in the table view.
You need the cell for a certain IndexPath to calculate its bounds. You can do it this way in any of the delegate functions of the UITableView : let row = tableView. cellForRow(at: indexPath) let cellHeight = (row?.
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text SubTitle text";
cell.detailTextLabel.numberOfLines = 0;
return cell;
}
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