[英]dynamic uitableviewcell height according to custom cell height
我想知道,有没有办法读取你将在你的uitableviewcell中使用的自定义tableview单元格的高度,然后你可以对你的uitableviewcell说这个--->高度?
I am not fully understand your question but do you want to set the height for each custom cell ? 我不完全理解你的问题,但是你想为每个自定义单元格设置高度吗? If yes then you can do it by : 如果是,那么您可以通过以下方式完成:
Let say I have custom cell at index 0 rest are my default cells or can be custom cell as well . 假设我在索引0处有自定义单元格其余是我的默认单元格,也可以是自定义单元格。
- (CGFloat)tableView:(UITableView *)_tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0 ) {
return 105.0;
}else {
return 80.0;
}
}
No, the height that you set in the xib/storyboard is for display purposes only and doesn't transfer over to code. 不,您在xib / storyboard中设置的高度仅用于显示目的 ,不会转移到代码。
The only way to change the height is from your custom subclass, by overriding tableView:heightForRowAtIndexPath:
. 更改高度的唯一方法是从您的自定义子类,通过重写tableView:heightForRowAtIndexPath:
.
If you have a lot of different heights, you could always subclass UITableViewCell and add a height
property which tableView:heightForRowAtIndexPath:
uses when it sees your subclass. 如果你有很多不同的高度,你可以随时继承UITableViewCell并添加一个tableView:heightForRowAtIndexPath:
在看到你的子类时使用的height
属性。 Then, in your storyboard, select your cell, go to the identity inspector, and add a User Defined Runtime Attribute for height with the value that you need. 然后,在故事板中,选择您的单元格,转到身份检查器,然后使用您需要的值添加高度的用户定义的运行时属性 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.