简体   繁体   English

iPhone中的自动tableView单元格大小是多少?

[英]Automatic tableView cell size in iPhone?

I want to make a UITableView which automatically adjust it's cell size by it's contents. 我想制作一个UITableView ,通过它的内容自动调整它的单元格大小。

The contents are from XML file and the data is just text. 内容来自XML文件,数据仅为文本。

I want to put the text in a cell and it should be automatically does word-wrap and support multi-line. 我想将文本放在cell ,它应该自动自动word-wrap并支持多行。

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 ? 您看过Three20图书馆吗? 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. 至少,您可以查看如何实现代码以调整单元格大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM