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?
5 Answers
You need to implement the
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
method in your UITableViewDelegate.
Comments
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..
1 Comment
There are 2 steps to change height of a table cell without any additional code:
- 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
.
Note that you MUST set BOTH of Table View's Row Height
attribute and Table View Cell's Row Height
attribute.
If you just set one of them, it won't work.
Comments
I found this answer to be the most informative and most up-to-date to change the height of a table view cell.
TL;DR
- 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