8

I am using a UITableView on an iPad and for some reason the UITableViewCell.textLabel's text is getting truncated even though there's plenty of space to display the text. I tried all of the following, none of which fixed it:

  1. Set a flexible width autosizing mask on the cell
  2. Calling [cell sizeToFit] after setting the text
  3. Calling [cell.textLabel setNumberOfLines:0] and [cell.textLabel setLineBreakMode:NSLineBreakByWordWrapping]

I haven't yet tried subclassing UITableViewCell and setting the frame explicitly in the layoutSubviews method. Trying to avoid that as I feel like there should be a better solution. I also don't want to resize the text--there is plenty of space to fit the text at the full font size.

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jamie Forrest
  • 10,895
  • 6
  • 51
  • 68
  • How are you displaying those numbers on the right side by the ">" ? Have you aded a custom accessory view? – rdelmar Jun 06 '13 at 14:35
  • I am adding a UILabel as a subview to the cell. However, I have tried commenting out the UILabel and it still doesn't work. – Jamie Forrest Jun 06 '13 at 14:58
  • So, if you comment that out, the cell is just a standard "Basic" cell with a disclosure indicator, nothing else? – rdelmar Jun 06 '13 at 15:15
  • Correct: `cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];` – Jamie Forrest Jun 06 '13 at 15:17
  • I can't duplicate your problem. You should try adding a background color to your label to make sure what its size is. When I do this, it shows the label going all the way up to the disclosure indicator – rdelmar Jun 06 '13 at 15:20

4 Answers4

7

u set set textLabel number of line 0

     cell.textLabel.numberOfLines=0;
     cell.textLabel.lineBreakMode=UILineBreakModeWordWrap; or NSLineBreakByWordWrapping;

hope it help you

kirti Chavda
  • 3,029
  • 2
  • 17
  • 29
4

Set the "setNumberOfLines" property of the label to wrap the text to required number of lines. If you don't want the "..." at the end of the text if it is too long then use

cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; or NSLineBreakByWordWrapping for ios 6 or more

Try to set height and width of textlable and tableviewcell dynamicaly refer this link

Community
  • 1
  • 1
0

The answer had nothing to do with UITableViewCell in the end. There was a section of the code truncating the text to display in the table view cell! Thanks everyone for the help up to this point.

Jamie Forrest
  • 10,895
  • 6
  • 51
  • 68
0

I had the same problem. this happened to me in ios 6 and this also happened to me with you customized cells. I used multiline and NSLineBreakByWordWrapping.

I've solved changing all labels to use NSLineBreakByCharWrapping

intropedro
  • 2,804
  • 1
  • 24
  • 25