什么是UITableViewCell的默认高度?

我认为这个信息会更容易find:-)

什么是UITableViewCell的默认高度? 它看起来像44像素,但我更愿意确定。

这是44个像素。 当然。 我永远不会忘记那个号码。

44px也是UIToolbar和UINavigationBar的默认高度。 (自动旋转到横向时,都切换到32像素。)

style = UITableViewStyleGrouped ,top&bottom单元格的默认高度实际上是45.0f (不是44.0f )。 而且,如果分组表只有一行,那么单元格高度将是46.0f

如果您想在任何设备上使用默认尺寸:UITableViewAutomaticDimension

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

尽pipe目前44个像素是默认值,但如果您的应用程序依赖于默认值设置,则这是一种有用的方法。

如果你想在飞行中计算这个,只需要分配一个虚拟表格单元并读取它的高度

 UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; int height = cell.frame.size.height ; 

这样你可以防御未来iOS版本的变化,但我认为这不太可能。

“当style = UITableViewStyleGrouped时,top&bottom单元格的默认高度实际上是45.0f(不是44.0f),而如果分组表格只有一行,那么单元格的高度就是46.0f。 这是不对的!! 实际上是44.0f! 我只是testing它!

这听起来是正确的。 但是为了确保你可以加载接口生成器,把UITableViewCell放到项目中,然后在检查器窗口中检查大小属性。 我现在没有我的MacBook,所以我无法检查。 但是,如果你没有从别人那里得到更好的答案,那么你可以自己检查一下。