【问题标题】:Get height of UITableViewCell [duplicate]获取 UITableViewCell 的高度 [重复]
【发布时间】:2013-10-27 21:47:54
【问题描述】:

我想将UITableViewCell 的高度设置为我在情节提要中指定的高度。

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    return cell.frame.size.height;
}

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

【问题讨论】:

  • 仅使用xcode 标签来回答有关 IDE 本身的问题。谢谢!

标签: ios objective-c uitableview height


【解决方案1】:

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

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

    return 64; // some value
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 2013-07-29
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    相关资源
    最近更新 更多