S.J. Lim
S.J. Lim

Reputation: 3165

How can I turn off UITableViewCell's delete mode?

I'm using UITableViewCell.

I'd like to programatically change the UITableViewCell's mode from Delete to Edit when user is canceled delete.

Please let me know how to change.

Thank you for your help.

Here is trying code.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {

    UITableViewCell *aCell;
    aCell = [self tableView:gbl_tableView cellForRowAtIndexPath:gbl_indexPath];

    if (buttonIndex == 0){
        NSUInteger row = (NSUInteger) [gbl_indexPath row];
        [userListStr removeObjectAtIndex:row];
        [userImage removeObjectAtIndex:row];
        [gbl_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:gbl_indexPath]
                             withRowAnimation:UITableViewRowAnimationAutomatic];
    }
    else if (buttonIndex == 1) {
        // When user canceled.  
        [aCell setEditing:NO animated:YES]; <==== ??? I can't know how.. This code don't work.

    }

}

enter image description here from delete to edit -> enter image description here

Upvotes: 0

Views: 112

Answers (2)

Joe
Joe

Reputation: 2987

Is it possible aCell is null/nil? I believe the proper way to pull the cell form the UITAbleViewController is something like:

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nowIndex];

In your case it would be

UITableViewCell *cell = [gbl_tableView cellForRowAtIndexPath: gbl_indexPath];

Upvotes: 1

CSolanaM
CSolanaM

Reputation: 3368

Have you tried this method?

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView  editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

You can return UITableViewCellEditingStyleNone

Upvotes: 1

Related Questions