I need to set the height for a single UITableViewCell in my UITableView programmatically. How can I do this?
I need this one cell to be 150 pixels high and all the others can stay at their default 44 pixels in height.
Thanks.
There is a delegate function for the UITableViewCell height.
Here you specify the indexPath of that particular cell and return your height for it
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == yourSection && indexPath.row == yourRow) {
return 150.0;
}
// "Else"
return someDefaultHeight;
}
You will have to know, or figure out what cell index you want to make the taller one. Lets say its your first cell.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) { //change 0 to whatever cell index you want taller
return 150;
}
else {
return 44;
}
}
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