mat*_*odv 17 iphone height uitableview
是否可以在分组表视图中修改仅一个单元格的高度?
我有一个包含3个和2个行的2个部分的表视图...我会改变第二部分第二行的行高...
我怎样才能做到这一点?
谢谢!
vod*_*ang 54
你可以看看这个方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
在您的情况下,代码应如下所示:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1 && indexPath.row == 1) {
return SPECIAL_HEIGHT;
}
return NORMAL_HEIGHT;
}
Run Code Online (Sandbox Code Playgroud)
在iOS 8及更高版本中,我们可以使用动态表视图单元格高度.
使用此功能UITableviewCell从其内容中获取高度,我们不需要编写heightForRowAtIndexPath
我只需要在viewDidLoad()中做
tableView.estimatedRowHeight = 44.0;
tableView.rowHeight = UITableViewAutomaticDimension;
Run Code Online (Sandbox Code Playgroud)
如果cell包含uilabel.然后应用约束uilabel
确保将Label --Lines--更改为0
细胞将自动生长,内容为uilabel:
| 归档时间: |
|
| 查看次数: |
40697 次 |
| 最近记录: |