views:

182

answers:

3

I have a grouped UITableView with a few sections. The text in some of the cells can get quite long, I was wondering how I could make the text word-wrap?

A: 

It looks like this question Custom Cell Height, right? I don't really get what word-wrap do, but I assume that you want to change the cell size according to the text length, is that right? So you can look at the above question and answer

vodkhang
Setting the cell height larger does not make the text fit. It still presents the "..." to the truncated text.
Sheehan Alam
"There is one label in the cell whose text is a NSString object and the length of string could be variable , due to this i cannot set a constant height to the cell in UITableViews : heightForCellAtIndex method. " (copied from the question), how about putting it into some UILabel and try again?
vodkhang
If I set the label property on the cell I can make it wordwrap. If the frame of the label exceeds the size of the cell, then I need to define a custom cell height. I guess both changes need to be made :)
Sheehan Alam
Yeah, I think so:)
vodkhang
A: 

set numberOfLines > 1 on your label and set an appropriate lineBreakMode as well. You might need to modify the frame of the label to have enough space. You can do this in tableView:willDisplayCell:forRowAtIndexPath: of your table view delegate.

Elfred
+1  A: 

eg

textLabel.numberOfLines = 0;

You can set this to a fixed number of lines if you prefer. It may be a good idea to set the lineBreakMode, and you will probably need to implement:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

using:

NSString sizeWithFont:constrainedToSize:
Paul Lynch