简体   繁体   English

如何使表格视图单元格动态变化?

[英]How do I make a table view cell dynamic in size?

I am using the 我正在使用

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

to make all the cells big enough for the biggest cell however I would like to make the cell big enough for its perspective contents. 使所有单元都足够大以容纳最大的单元,但是我想使单元足够大以容纳其透视图内容。 Any help is appreciated. 任何帮助表示赞赏。

You can't change the width of individual cells, that is part of the UITableView. 您不能更改单个单元格的宽度,这是UITableView的一部分。 You can return a different value for the tableView:heightForRowAtIndexPath: for each row, that is how you make rows different heights. 您可以为每一行的tableView:heightForRowAtIndexPath:返回不同的值,这就是使行具有不同的高度的方法。 For example: 例如:

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

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

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