0

I have a UITableView and I'm having trouble with the formatting of the cells.

This is what it looks like this: "Image Link"

As you can see, the cells with a percent grade have the textLabel (the class name) higher than the cells without the percent grade. The problem is in the cellForRowAtIndexPath method in the UITableViewDelegate. I set the text of the textLabel (the part of the table view with the class name) and then if the detailTextLabel has a percent, I set the cell.detailTextLabel.numberOfLines = 2;. I don't see why this affects the textLabel though. I thought the two labels in the content view were independent of each other.

How would I fix this problem and get my labels to format correctly?

Tulon
  • 4,011
  • 6
  • 36
  • 56
user3451350
  • 61
  • 2
  • 8
  • Why not set the detail label to always have 2 lines? You don't need to have any text in the second line. – rdelmar May 12 '14 at 18:53
  • I could do that but then the class name will be slightly higher, because the `[label sizeToFit]` will make it so that there are two lines where the class name is on the top line... Is there some way I can keep the class name (ie the `textLabel`) as a one line label while making the `detailTextLabel` always two? – user3451350 May 12 '14 at 19:30
  • i don't think it be higher if there's no text, [sizeToFit] consider the text in the label and then calculate the size, i think :) – Dekel Maman May 12 '14 at 22:08
  • Use Custom UITableViewCell. – Ricky May 12 '14 at 23:24
  • @DekelMaman I'll try that tomorrow. – user3451350 May 13 '14 at 01:37
  • @Ricky if I do a custom UITableViewCell, what specific settings would you recommend changing to allow that? – user3451350 May 13 '14 at 01:43
  • 1
    If you do a custom UITableViewCell, you can have 3 UILabels for 1 tableCell (With %) and another UITableViewCell with only 2 UILabels (Without %). You will need to know which type of cell to use during the cell creation in tableView:cellForRowAtIndexPath: – Ricky May 13 '14 at 03:55
  • @Ricky yeah that's will be the right way to do that... :) – Dekel Maman May 13 '14 at 05:12
  • I think @ViruMax has an easier solution, use the `detailTextLabel` but just use a `UILabel` for the class name... So it's just the class name I have to re add – user3451350 May 13 '14 at 23:17

1 Answers1

0

You can solve this problem by adding two separate new labels in your cell. Don't use the default labels. You can refer to this link for code snippet and for more detailed explanation.

Community
  • 1
  • 1
ViruMax
  • 1,216
  • 3
  • 16
  • 41