Is it possible to modify height of only one cell in a grouped table view?
I have a table view with 2 sections of 3 and 2 rows... I would change row height of the second row of the second section...
How can I do this?
Thanks!
A few ins-and-outs aside, all you really have to do is: Use Auto Layout for the UI elements inside the table view cells. Set the table view rowHeight to UITableViewAutomaticDimension . Set the estimatedRowHeight or implement the height estimation delegate method.
You can look at this method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
In your case, the code should look like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1 && indexPath.row == 1) {
return SPECIAL_HEIGHT;
}
return NORMAL_HEIGHT;
}
You can look for more details about the method here
In iOS 8 and above we can use the Dynamic Table View Cell Height.
Using this feature UITableviewCell
get its height from its content and We don't need to write heightForRowAtIndexPath
All I have to do in viewDidLoad()
tableView.estimatedRowHeight = 44.0;
tableView.rowHeight = UITableViewAutomaticDimension;
If cell
contains uilabel
. then apply constraints to uilabel
Make sure you change Label --Lines-- to 0
The cell will grow automatically with content of uilabel
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With