Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Objective c TableViewCell自动高度_Objective C_Iphone_Autolayout_Uitableview - Fatal编程技术网

Objective c TableViewCell自动高度

Objective c TableViewCell自动高度,objective-c,iphone,autolayout,uitableview,Objective C,Iphone,Autolayout,Uitableview,我在UITableViewCell中有一个标签,我希望我的高度TableViewCell根据标签高度自动调整 } -CGFloattableView:UITableView*tableView RowAtIndexPath的高度:NSIndexPath*indexPath{ 返回165; } -voidtableView:UITableView*tableView didSelectRowatineXpath:NSIndexPath*indexPath{ //窃听一条推特 } 用于在viewD

我在UITableViewCell中有一个标签,我希望我的高度TableViewCell根据标签高度自动调整

}

-CGFloattableView:UITableView*tableView RowAtIndexPath的高度:NSIndexPath*indexPath{ 返回165; } -voidtableView:UITableView*tableView didSelectRowatineXpath:NSIndexPath*indexPath{ //窃听一条推特 }
用于在viewDidLoad中设置UITableViewCell的动态高度

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

 -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
此选项可根据内容高度设置自动单元格高度

让我知道这是否有效

或作为自动标注的方法

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

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

用于在viewDidLoad中设置UITableViewCell的动态高度

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

 -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
此选项可根据内容高度设置自动单元格高度

让我知道这是否有效

或作为自动标注的方法

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

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

获取动态更新的高度

-添加这些方法

===========

目标C ======

敏捷的
获取动态更新的高度

-添加这些方法

===========

目标C ======

敏捷的 首先转到情节提要上UITableViewCell标签的属性检查器,并将换行符属性设置为Word Wrap。现在,标签的约束非常重要

仅提供顶部、底部、前导和尾随约束,这样单元格就可以根据标签的内容调整其高度

然后在viewDidLoad中或为tableview设置委托的位置添加以下代码

首先转到情节提要上UITableViewCell标签的属性检查器,并将换行符属性设置为Word Wrap。现在,标签的约束非常重要

仅提供顶部、底部、前导和尾随约束,这样单元格就可以根据标签的内容调整其高度

然后在viewDidLoad中或为tableview设置委托的位置添加以下代码


您使用的是autolayout???,而不仅仅是返回UITableViewAutomaticDimension(高度为ROWATINDEXPATH)。。但条件是,您的约束应正确附加您正在使用的autolayout???,而不仅仅是返回UITableViewAutomaticDimension(高度为RowAtIndexPath)。。但条件是你的约束条件应该适当地附加在返回165上;当UITableViewAutomaticDimension处于RowAtIndexPath方法的高度时不工作-CGFloattableView:UITableView*tableView UITableViewAutomaticDimension:NSIndexPath*indexPath{return UITableViewAutomaticDimension;}替换return 165;如果UITableViewAutomaticDimension处于高度FORROWATINDEXPATH方法不工作-CGFloattableView:UITableView*tableView UITableViewAutomaticDimension:NSIndexPath*indexPath{return UITableViewAutomaticDimension;}
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}
self.yourTableView.estimatedRowHeight = 52.0; // Your desired minimum height for the cell.
self.yourTableView.rowHeight = UITableViewAutomaticDimension;