ios - UITableViewCell 框架高度始终为 44px

标签 ios objective-c uitableview ios6 heightforrowatindexpath

我正在使用返回 100 的 heightForRowAtIndexPath: 方法设置单元格的高度。 但在 cellForRowAtIndexPath 方法中,单元格的框架高度始终为 44px。

以下是我的代码。

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    [cell setBackgroundColor:[UIColor redColor]];
    [cell.contentView setBackgroundColor:[UIColor redColor]];
    cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
    NSLog(@"%f %f", cell.frame.size.height, cell.contentView.frame.size.height);
    return  cell;
}

NSLog 语句打印“44px 44px”。

我可以使用这个语句得到正确的高度

CGFloat height = [tableView heightForRowAtIndexPath:indexPath];

最佳答案

分配单元格时不会调用您的委托(delegate)方法。 initWithStyle 总是返回高度为 44 的单元格,除非您在子类中覆盖它。

关于ios - UITableViewCell 框架高度始终为 44px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14504448/

相关文章:

ios - 从初始化器返回之前不调用 Super.init

android - 将 Firebase 与 Titanium 集成?

objective-c - 如何打印 Cocoa 中字符串迭代创建的 Unicode?

iphone - 提取 iPod 库原始 PCM 样本并播放音效

ios - Facebook iOS sdk 好友列表返回空

ios - 右侧带有部分索引的 SwiftUI 列表?

ios - ReactiveSwift 中的 API 请求

objective-c - 关于应用内购买

ios - 如何在 ios 中使用 NSDictionary 将两个 NSArray 对象显示为 UITableview 的部分

ios - Swift 自定义 UITableViewCell 标签始终为零