4
votes

I have a second confirmation dialog that appears when a user decides to delete a UITableViewCell. Here is my table view in its normal state:

Normal


And here it is when the whole table goes into editing mode:

Normal editing mode


Now when the user taps one of the red minus signs on the left, the cell goes into delete confirmation mode:

Delete confirmation mode


If the user then taps the delete button that has just appeared, this action sheet appears:

Second confirmation


This is where the problem arises. If the user confirms that they want to delete the map, all is well. But if the cancel button is pressed, the action sheet disappears, but the table view still looks like this:

The delete confirmation button should no longer be in its selected state, and should have hidden itself from view

The issue is that the delete confirmation button should no longer be in its selected state, and should have hidden itself from view. As you can see it hasn't. My searches in the documentation have ended with no results. I don't want to setEditing:NO because I want the table to remain in its normal editing state. Any ideas?

Edit 1: Here is what goes on inside tableView:commitEditingStyle:forRowAtIndexPath:

- (void)tableView:(UITableView*)tableView commitEditingStyle:
    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
    NSInteger finalIndex = [self getFinalIndexForIndexPath:indexPath];

    NSString* mapTitle = ((PreviewDataObject*)[[[SingletonDataController sharedSingleton]
        getImportedOrSavedMapPreviews:masterIdentifierString] 
        objectAtIndex:finalIndex]).titleString;

    UIActionSheetWithIndexPath* sheet = [[UIActionSheetWithIndexPath alloc] initWithTitle:
        [NSString stringWithFormat:@"Are you sure you want to delete the map '%@'?", 
        mapTitle] delegate:self cancelButtonTitle:@"Cancel" 
        destructiveButtonTitle:@"Delete Map" otherButtonTitles:nil];
    sheet.indexPath = indexPath;
    [sheet showFromTabBar:[AppDelegate appDelegate].tabBarController.tabBar];
    [sheet release];
}
4
can u show the code of - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath - Anshuk Garg
Can you please tell us what is your array name in here? - vishiphone
In commitEditingStyle, I don't actually do any deleting; I just present the action sheet which prompts the user if they really want to delete the map. - eric.mitchell

4 Answers

1
votes

After that, you may as well present an AlertView asking if they really, really, really want to delete.

The 2-step process of turning on the button and then pressing delete should be plenty of confirmation.

Doing what you're doing does not seem to me to be standard practice, and once you get into that area you're going to find holes in the framework.

1
votes

I agree with the above discussion that needing to hit delete 3 times is a bad idea.

However, for other actions there may be a good reason for resetting the row. The simplest solution is just reloading that one row.

Swift 2.2:

tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
0
votes

Just try this and tell me its working for you or not.

  -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if (editingStyle == UITableViewCellEditingStyleDelete)
       {
           // Delete the row from the data source.

           [arr removeObjectAtIndex:indexPath.row];


           [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
         }
        else if (editingStyle == UITableViewCellEditingStyleInsert)
        {
          // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
        }   
    }
0
votes

Simply exit the editing mode (Swift):

tableView.setEditing(false, animated: true)