Set UITableViewCell secondaryText multiple lines

110 Views Asked by At

I'm using UIListContentConfiguration to config cell properties on iOS 14. The cell's style is standard Right Detail. I was able to set the detail text field displaying in multiple lines on the right of the main text just using

cell.DetailTextLabel.Lines = 0

But now I can't do the same thing with UIListContentConfiguration by using

content.SecondaryTextProperties.NumberOfLines = 0

The secondary text jumps to a new line instead of staying on the right of the main text when it gets long.

What should I do?

It's written in C# MAUI but I think it's similar to native iOS as well:

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
    var cell = tableView.DequeueReusableCell(cellData, indexPath);
    cell.AccessoryView = null;
    cell.UserInteractionEnabled = false;
    cell.Accessory = UITableViewCellAccessory.None;

    var content = cell.DefaultContentConfiguration;
    content.Text = "Main text";
    content.TextProperties.Color = UIColor.Black;
    content.SecondaryText = "Quite a longggggggggggggggg text";
    content.SecondaryTextProperties.Color = UIColor.Gray;
    content.SecondaryTextProperties.NumberOfLines = 0;
    cell.SizeToFit();
    cell.ContentConfiguration = content;
    return cell;
}
0

There are 0 best solutions below