我想让UITableViewCell
变得更大。我该怎么做?我已经尝试过调整它的框架大小,但仍然没有任何变化。我该怎么办呢?
我想让UITableViewCell
变得更大。我该怎么做?我已经尝试过调整它的框架大小,但仍然没有任何变化。我该怎么办呢?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
在你的UITableViewDelegate中有一个方法。
你可以这样做...
//Change the Height of the Cell [Default is 44]:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == 1) {
return 90;
}
}
return 44;
}
我希望这能帮到你。
更改表格单元格高度的方法有2步,无需任何额外代码:
Table View
。在大小检查器
中更改行高
属性。Table View Cell
后,在大小检查器
中更改行高
属性。请注意,必须同时设置Table View的行高
属性和Table View Cell的行高
属性。缺一不可。
如果只设置其中一个,将无法生效。
我发现这个答案对于改变表格视图单元的高度来说是最具信息量和最新的。
简而言之:
在viewDidLayoutSubviews
方法中启用表格视图的行高估算。
self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.estimatedRowHeight = 44.0; // 设置为你的“平均”单元高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == tableView1)
{
return 55;
}
else if(tableView == tableView2)
{
return 75;
}
}
这可能会对你有所帮助。