我正在使用返回 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/