Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取UITableViewCell的动态高度_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 获取UITableViewCell的动态高度

Ios 获取UITableViewCell的动态高度,ios,objective-c,uitableview,Ios,Objective C,Uitableview,Im在UITableView单元格内使用UITableView。 我希望单元格根据tableView的内容大小调整大小 我已经试着通过测量每个细胞的高度 CGRect frame = [self.Table rectForRowAtIndexPath:indexPath]; 但它并没有给我返回正确的细胞高度。这些单元格根据文本获取动态高度。在viewDidLoad方法中 self.table.estimatedRowHeight = 44.0 ; self.table.rowHeight =

Im在
UITableView单元格内使用
UITableView
。 我希望单元格根据tableView的内容大小调整大小

我已经试着通过测量每个细胞的高度

 CGRect frame = [self.Table rectForRowAtIndexPath:indexPath];

但它并没有给我返回正确的细胞高度。这些单元格根据文本获取动态高度。

在viewDidLoad方法中

self.table.estimatedRowHeight = 44.0 ;
self.table.rowHeight = UITableViewAutomaticDimension;

//numberOfLinesOfYourLabel should be 1
然后

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension
}

在viewDidLoad方法中

self.table.estimatedRowHeight = 44.0 ;
self.table.rowHeight = UITableViewAutomaticDimension;

//numberOfLinesOfYourLabel should be 1
然后

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension
}
  • 在mainTableview的cellForRow方法中重新加载subtableview
  • 在mainTableview的cellForRow方法中重新加载subtableview
参考:参考此答案我的单元格正在获得动态高度,我希望我的tableview能够根据单元格大小调整大小,因为我想禁用tableview的滚动。@Ahmad堆栈溢出中已经有很多关于你的问题的答案,这是Arun给出的最佳建议答案之一,跟随它。@the_dahiya_boy我的问题与此链接相同参考:参考此答案我的单元格获得动态高度,我希望我的tableview根据单元格大小调整大小,因为我想禁用tableview的滚动。@Ahmad你的问题有很多答案已经出现在stack overflow中,Arun给出的一个最好的建议答案,跟随它。@the_dahiya_boy我的问题与此链接相同,我的单元格根据文本获得动态高度,设置高度不是一个选项,因为im使用4种不同类型的单元格,每个单元格有2-3个不同字体和字体大小的标签。是的,您必须根据heightForRow方法中的文本和字体计算单元格高度。我的单元格根据文本获得动态高度,设置高度不是一个选项,因为im使用4种不同类型的单元格,每个单元格有2-3个不同字体和字体大小的标签。是的,您必须根据heightForRow方法中的文本和字体计算单元格高度