开发者

Automatic tableView cell size in iPhone?

I want to make a UITableView 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 automatica开发者_如何学Golly does word-wrap and support multi-line.

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

Thank you ;)


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

- (CGFloat)tableView:(UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath    {
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;

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜