Take the 2-minute tour ×

I want to make a tableView which automatically adjust it's cell size by it's contents.

The contents are from XML file and the data is just text.

I want to put the text in a cell and it should be automatically does word-wrap and support multi-line.

So each cell can have different height. Is this possible?? or any idea?

Thank you ;)

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Yes it is possible. Make use of the following method for doing it,

CGSize cellHeight;
if (indexPath.row == 0) {
    cellHeight = [yourXMLContents sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(300.0, 1000.0) lineBreakMode:UILineBreakModeWordWrap];
    return cellHeight.height + 20;
}  else 
    return  30;


share|improve this answer
I tried this but for some reason the return value from heightForRowAtIndexPath method is over 50, but the cell size is always 46 in cellForRowAtIndexPath method. Why is that? heightForRowAtIndexPath is called first, and then cellForRowAtIndexPath is called. –  SeniorLee Dec 31 '10 at 6:53
Finally it works. Thank you for your tip! –  SeniorLee Dec 31 '10 at 15:26
add comment

Have you looked at the three20 library? It'll resize the cells to fit the content. In the very least, you can look at how the code is implemented to resize cells.

share|improve this answer
thanks I've never heard of three20. But now I can at least look at it how it does. BTW are you Korean? –  SeniorLee Dec 31 '10 at 5:16
yessir, i am korean :) –  donkim Dec 31 '10 at 5:24
glad to see korean in StackOverflow ;) –  SeniorLee Dec 31 '10 at 6:54
add comment

Your Answer


