ios 更改 UITableViewCell 的高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8543846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change Height of a UITableViewCell
提问by user973985
I want to make a UITableViewCell
bigger. How can I do this, I have tried adjusting its frame but nothing happens. What can I do?
我想做一个UITableViewCell
更大的。我该怎么做,我试过调整它的框架,但没有任何反应。我能做什么?
回答by Shane Powell
You need to implement the
你需要实现
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
method in your UITableViewDelegate.
回答by User-1070892
You can do like this..
你可以这样做..
//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;
}
I hope this will help you..
我希望这能帮到您..
回答by scaryguy
There are 2 steps to change height of a table cell withoutany additional code:
无需任何附加代码即可更改表格单元格的高度有 2 个步骤:
- Select your
Table View
from your Storyboard. In theSize Inspector
changeRow Height
. - Select your
Table View Cell
and while it's selected in theSize Inspector
change theRow Height
.
Table View
从您的故事板中选择您的。在Size Inspector
变化中Row Height
。- 选择您的
Table View Cell
和 在Size Inspector
更改Row Height
.
Note that you MUSTset BOTHof Table View's Row Height
attribute and Table View Cell's Row Height
attribute.
请注意,您必须设置BOTH表视图的的Row Height
属性和表格视图单元格的Row Height
属性。
If you just set one of them, it won't work.
如果您只设置其中之一,它将不起作用。
回答by ChrisJF
I found this answerto be the most informative and most up-to-date to change the height of a table view cell.
我发现这个答案是更改表格视图单元格高度的最有用和最新的答案。
TL;DR
TL; 博士
- Take extra care when making your Auto Layout constraints
Enable row height estimation on your table view in the
viewDidLayoutSubviews
method.self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.estimatedRowHeight = 44.0; // set to whatever your "average" cell height is
- 制作自动布局约束时要格外小心
在
viewDidLayoutSubviews
方法中在您的表视图上启用行高估计。self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.estimatedRowHeight = 44.0; // 设置为您的“平均”单元格高度
回答by Nithinbemitk
You can use this code for changing the height of different tableview
您可以使用此代码更改不同 tableview 的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == tableView1)
{
return 55;
}
else if(tableView == tableView2)
{
return 75;
}
}
This may help you.
这可能对你有帮助。