Objective c TableViewCell自动高度
我在UITableViewCell中有一个标签,我希望我的高度TableViewCell根据标签高度自动调整 } -CGFloattableView:UITableView*tableView RowAtIndexPath的高度:NSIndexPath*indexPath{ 返回165; } -voidtableView:UITableView*tableView didSelectRowatineXpath:NSIndexPath*indexPath{ //窃听一条推特 }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
用于在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;