1
votes

I am calling heightForRowAtIndexPath to adjust my cells. When I edit my table view to delete cells the height of the cells stay fixed so the cells overlap which creates not a very appealing image. I would like to know how to change the height of the cell when deleting of the cells begins.

This is my current code

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

Favorites *favorite = [fetchedResultsController objectAtIndexPath:indexPath];
NSString *cellText = favorite.name;
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];

CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);

CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

return labelSize.height + 20;

}

Any help will be appreciated! Thanks

2

2 Answers

0
votes
- (void)tableView:(UITableView *)tableView commitEditingStyle: UITableViewCellEditingStyle)editingStyle 
       forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
       [tableView reloadTable];
    }   
}

and you can change a property which will tell u want the right height, and read its value from heightForRowAtIndexPath

0
votes

Your problem is that if numberOfLines is 0 for a label in your cell (which it probably is so that your cell can expand), then the label will expand again when delete slides in, causing the ugly overlap. A worthy alternative is to truncate the text when the delete slide comes in. To do this you need to set the number of lines when you make the cell.

cell.textLabel.numberOfLines = textLabelheight/textLabelFontSize;

You probably already know textLabelHeight and textLabelFontSize, cos you worked it out when you adjusted the cell height.