UITableView deleting row reduced table row height

PruitIgoe

When I delete a row from my tableview the remaining rows height get's reduced by about 20 or so points/pixels/whatever Apple table rows are measured in. When I first display the table the row fits the content - I configure the content this way:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Set up the cell...
    [self configureCell:cell atIndexPath:indexPath];

    return cell;
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    Favorite *thisFavorite = [self.arrResults objectAtIndex:[indexPath row]];

    NSMutableAttributedString* strAtttributedText;

    // Define general attributes for the entire text
    NSDictionary *attribs = @{
                              NSForegroundColorAttributeName: cell.textLabel.textColor,
                              NSFontAttributeName: cell.textLabel.font
                              };
    NSString* strCellText = [NSString stringWithFormat:@"%@\n%@\n%@", thisFavorite.favName, thisFavorite.favAddress, thisFavorite.favCity];


    //get location of first return TO DO - need to figure out how to return the range from the string above
    NSRange newLineRange = [strCellText rangeOfString: @"\n"];
    NSRange firstLineRange = NSMakeRange(0, newLineRange.location);
    NSRange restOfTextRange = NSMakeRange(newLineRange.location + 1, strCellText.length-newLineRange.location-1);

    strAtttributedText = [[NSMutableAttributedString alloc] initWithString:strCellText attributes:attribs];


    [strAtttributedText setAttributes:@{NSForegroundColorAttributeName:MPL_BLUE} range:firstLineRange];

    [strAtttributedText setAttributes:@{NSForegroundColorAttributeName:MPL_LIGHTGRAY, NSFontAttributeName:TABLE_CELL_FONT} range:restOfTextRange];

    cell.textLabel.attributedText = strAtttributedText;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;

}

and I am deleting the row this way:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        Favorite* thisFavorite = [self.arrResults objectAtIndex:indexPath.row];

        [self.tableView beginUpdates];

        NSArray* arrIndexPaths = [NSArray arrayWithObjects:indexPath, nil];
        [self.tableView deleteRowsAtIndexPaths:arrIndexPaths withRowAnimation:UITableViewRowAnimationFade];
        [self.arrResults removeObjectAtIndex:indexPath.row];

        [self.tableView endUpdates];

        [self.myController deleteManagedObject:thisFavorite];

    }
}

where would I manage the cell height in this process?

I can get the initial cell frame (they are all the same content style - name\naddress\ncity,state,zip) from here:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    self.cellSize = cell.frame;
}

I tried dropping self.tableview.rowHeight = self.cellSize.size.height inbetween begin and end editing but it had no affect.

Any help would be appreciated.

Rony Rozen

You should implement this method and return a constant height for your cells (I didn't see it in the code snippet you posted):

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   return someConstantIntValue;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

deleting a row from table

From Dev

Deleting row in Sqlite table

From Dev

deleting a row in a table

From Dev

Set row height of a UITableView according to the cell in that row

From Dev

UITableView default row height Xcode

From Dev

Animation issue when deleting the last row of UITableView

From Dev

UITableView Deleting Row. Swift 2

From Dev

Animation issue when deleting the last row of UITableView

From Dev

Deleting table row by id with jQuery

From Dev

Deleting Row in table using jQuery

From Dev

Dynamic UITableView row height using UIStackView?

From Dev

How to resize the UITableView row height in Objective C

From Dev

Accessing the Row Height in Dynamic UITableView Prototypes

From Dev

Reducing HTML Table Row Height

From Dev

Auto height of table-row

From Dev

Change table row height - Bootstrap

From Dev

Table with dynamic row height issue

From Dev

Active Reports Table Row Height

From Dev

Table with dynamic row height issue

From Dev

Table with variable row height in tkinter

From Dev

Unable to set row height equal to table height

From Dev

UITableView: automatically set height for the row and fix it with max height constant

From Dev

Deleting row in table with Jquery in mvc project

From Dev

404 Error When Deleting Table Row in Azure

From Dev

"On Delete Cascade" if deleting a row from the child table

From Dev

Deleting rows and insert row in pivot table laravel

From Dev

Deleting Row from users table PHP MYSQL

From Dev

Deleting a Row in a rowReorder Table Resets Reordering

From Dev

Always deleting last row of table in MVC View