我需要从 tableView:cellForRowAtIndexPath 方法中获取 tableView 单元格的高度。
例如,我在 tableView:heightForRowAtIndexPath
中设置行的高度以返回 200。但是在 tableView:cellForRowAtIndexPath
中,当我执行 NSLog(@"cell height: %f", cell.contentView.frame.size.height);
我没有得到200,我得到默认的单元格高度 44.0。然而,单元格的大小在模拟器中视觉上是正确的。必须有一种方法可以直接获取 heightForRowAtIndexPath
中指定的大小,而不必将其存储在单独的变量中 - 不是吗?
最佳答案
您可以在 tableView:cellForRowAtIndexPath
中调用。
这是一个例子:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat cellHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPath];
}
关于objective-c - 如何从 tableView :cellForRowAtIndexPath? 中访问 tableView 单元格的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12203027/