如何使表格视图单元格动态大小?

时间:2011-06-25 02:54:59

标签: iphone objective-c cocoa-touch ipad uitableview

我正在使用

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

使所有单元格足够大以容纳最大的单元格但是我想使单元格足够大以获得其透视内容。 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:3)

您无法更改单个单元格的宽度,这是UITableView的一部分。您可以为每一行的tableView:heightForRowAtIndexPath:返回不同的值,即行的不同高度。例如:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  MyThing *theThing = [arrayOfData objectAtIndex:indexPath.row];
  return theThing.linesOfData * 17; //made up number for font height
}