A: 

Subclass UITableViewCell, and in the subclass's loadView method, create a UILabel inside its contentView. Set this label to have the appropriate wrapping and location.

Adam Ernst
Can I specify it in this method?- (UITableViewCell *)tableViewCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Daniel Kindler
Because that is where I changed the text size, and It worked
Daniel Kindler
You cannot specify it all in that method. You will need to change the height of each cell, depending on the length of the text you want to display. You will also need to set the maximum number of lines that UILabel can display to a number greater than 1.
mmc
A: 

Adam has it right. For a little more detail (as well as a method that scrolls lightning fast) you can check out this entry on atebits.com that bypasses the UILabel approach entirely.

Loren Brichter's UITableViewCell subclassing example

You can also look at the TableViewSuite example from developer.apple.com It contains 5 different examples, in increasing complexity, for building custom TableViews. The last example is structurally very similar to the tutorial on atebits.com.

Lecture 8 of the Stanford iPhone course is also all about Scroll and TableViews, and has some examples of subclassing UITableViewCell.

iPhone Course

mmc
+2  A: 

You can do it without subclassing UITableViewCell.

In the method tableView:cellForRowAtIndexPath:, create a basic UITableViewCell and change the properties of the UILabel contained in this cell. Change the maximum number of lines to fit more text in your cell.

Unfortunately, the label of the cell is not accessible by properties, so you need to fetch it with the subviews property.

Of course this uses an implementation detail of UITableViewCell, so it might break with future releases of the SDK. Use with care.

Here is an example:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"YourCellId"];
    if (cell == nil)
    {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"YourCellId"] autorelease];
     cell.font = [UIFont systemFontOfSize:16];
     UILabel* cellLabel = [cell.contentView.subviews objectAtIndex:0];
     [cellLabel setNumberOfLines:3];
    }
    cell.text = @"Your text";
    return cell;
}

Update:

To set the row height to fit the text, you can do the following:

1. Set the cell height to fit the text.

You need something like this:

CGSize textSize = [text sizeWithFont:font
       constrainedToSize:CGSizeMake(313, 1000)
        lineBreakMode:UILineBreakModeWordWrap];
cell.frame = CGRectMake(0.0f, 0.0f, 320.0, textSize.height);

2. Return the cell height in the tableView:heightForRowAtIndexPath: method.

For example like this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [self tableView:(UITableView*)self.view cellForRowAtIndexPath:indexPath];
    CGRect cellFrame = cell.frame;
    return cellFrame.size.height;
}
henning77
Thanks! But In my awakeFromNib, I have this code "self.jokeTableView.rowHeight = 70.0;"How do I make it so that the rowHeight changes depending on how much text is needed to fit?
Daniel Kindler
I added an example of how to do this in my answer. Hope it helps.
henning77
A: 

This thread might help you.

Alex Reynolds