获取UITableViewCell的高度

时间:2013-10-18 22:29:11

标签: ios objective-c uitableview height

我将我的UITableViewCell的高度设置为我在故事板中指定的高度。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    return cell.frame.size.height;
}

使用此代码,应用程序崩溃。

1 个答案:

答案 0 :(得分:5)

您必须明确设置高度。在-cellForRowAtIndexPath:中调用– tableView:heightForRowAtIndexPath:会在两种方法之间创建无限循环。这是表格视图的常见错误。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

    return 64; // some value
}
相关问题