views:

2678

answers:

4

I have a UITableView that has a disclosure button on every row. When the table is put into edit mode and the the Deletion control is pressed ("-" sign), the Delete Button shows, however the disclosure button is not replaced, but instead just slides to the left of the delete button.

The apple UITableView guide explains the delegates for everything it seems except for the delegate that is called when the "-" sign is pressed, but before the delete button is displayed.

I would just like to suppress the disclosure indicator while the delete button is shown.

I'm guessing that I am missing something... I have set the setHidesAccessoryWhenEditing:NO on the cells of the table so that the indicator is displayed to indicate to the user that if they select the row, they can edit it...

The behavior I am trying to copy is done in the contacts app when a contact is edited. Any help would be greatly appreciated...

Thanks, Greg

+1  A: 

The disclosure indicator is managed by tableView:accessoryTypeForRowWithIndexPath: so maybe you could change the accessory type while in editing mode.

I believe there's a tableView:accessoryButtonTappedForRowWithIndexPath:, maybe there you can note that you're going to edit mode and then change what the tableView:accessoryTypeForRowWithIndexPath: returns for each row - no accessory when in edit mode.

I would give it a try.

Here is a calling sequence (not sure if that helps) description/tutorial/examples from Apple reference about how to go about Inserting and Deleting Rows in Editing Mode.

stefanB
+3  A: 

The standard way to do this is to use cell.hidesAccessoryWhenEditing = YES, and that editing is a modal action in which navigation is typically disabled.

The Contacts application actually uses custom table cells, and I wouldn't be surprised if it didn't so much use an accessory as have an image located on the cell's right edge, judging by its behaviour.

If you want to know when the delete button appears, I'd suggest that you try installing a Key-Value observer on the cell's showingDeleteConfirmation property, like so:

[cell addObserver: self forKeyPath: @"showingDeleteConfirmation"
          options: NSKeyValueObservingOptionNew context: NULL];

Then you implement the observer callback method:

- (void)observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object
                        change: (NSDictionary *) change context: (void *) context
{
    if ( [keyPath isEqualToString: @"showingDeleteConfirmation"] )
    {
        UITableViewCell * cell = (UITableViewCell *) object;
        BOOL isShowing = [[change objectForKey: NSKeyValueChangeNewKey] boolValue];
        if ( isShowing == NO )
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        else
            cell.accessoryType = UITableViewCellAccessoryNone;
    }
}

I should note that I'm not sure whether the UITableViewCell class is KVO-compliant for this property, but it's got to be worth a try…

Jim Dovey
Jim,Works like a charm! I really appreciate you taking the time to respond...Thanks,Greg
Greg Wobig
In case anyone happens across your solution, just to be complete, add:UITableViewCell * cell = object;also:Change if ( isShowing ) -> if (! isShowing)...
Greg Wobig
Jim Dovey
+1  A: 

My comment to Jim's solution didn't come across very well... Here is the version that solved the problem for me... Thanks again Jim!

   - (void)observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object
                        change: (NSDictionary *) change context: (void *) context
  {
    UITableViewCell * cell = object;
    if ( [keyPath isEqualToString: @"showingDeleteConfirmation"] )
    {
        BOOL isShowing = [[change objectForKey: NSKeyValueChangeNewKey] boolValue];
        if ( !isShowing )
     {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
     else
     {

            cell.accessoryType = UITableViewCellAccessoryNone;
     }
    }
}

Greg Wobig
+1  A: 

Or when you are creating your cell you can define the accessory type: cell.editingAccessoryType = UITableViewCellAccessoryNone;

Aram