UITableView, intercepting Edit mode

后端 未结 4 934
-上瘾入骨i
-上瘾入骨i 2021-02-13 13:59

I\'m curious if it\'s possible to intercept the default methods of \'Edit\' mode on a UITableView. Typically you get a free \'delete\' button if you side swipe a UITableViewCell

4条回答
  •  野的像风
    2021-02-13 14:52

    Editing is implemented as a method on your UITableView’s delegate object. In your table controller, have whatever control activates editing call this:

    [tableView setEditing: YES animated: YES];
    

    Then, make sure that your delegate object implements this:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
                UIAlertView *alert = [[UIAlertView alloc] 
                    initWithTitle: @"Delete" 
                    message: @"Do you really want to delete “George W. Bush”?" 
                    delegate: self
                    cancelButtonTitle: @"Cancel"
                    otherButtonTitles: @"Of course!", nil];
        }
    }
    

    …or a more standard action might be:

    [itemList removeObjectAtIndex:indexPath.row];
    [table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    

提交回复
热议问题