Delete control button in UITableview edit mode not working

I used edit mode UITableview

on button click but every time it goes into edit mode and I press delete button nothing happens. I have a view controller with UITableview

on it. I have set up my delegate list and tables as well as all my edit callbacks. Everything works (like reordering the cells), but whenever I try to delete by clicking the delete button, the delete button doesn't appear.

I got desperate as it seems like a really simple problem, but no matter what I try, it doesn't seem to work.

This is how I implement edit mode

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

(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [favoriteCurrencyValueList removeObjectForKey:[favoriteCurrencyList objectAtIndex:indexPath.row]];
    [favoriteCurrencyList removeObjectAtIndex:indexPath.row];
    NSUserDefaults *defaultSettings = [NSUserDefaults standardUserDefaults];
    [defaultSettings setObject:favoriteCurrencyList forKey:@"FavoriteCurrencies"];
    [defaultSettings setObject:favoriteCurrencyValueList forKey:@"PastValues"];
    [defaultSettings synchronize];
    [self.favoriteCurrencyTable beginUpdates];
    [self.favoriteCurrencyTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:(UITableViewRowAnimation)UITableViewRowAnimationLeft];
    [self.favoriteCurrencyTable endUpdates];
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    indexPathSelected = indexPath;
    //[self.view endEditing:YES];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    [self.favoriteCurrencyList exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];

    [[NSUserDefaults standardUserDefaults] setObject:self.favoriteCurrencyList forKey:@"FavoriteCurrencies"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

      

This is what sets the edit mode

- (IBAction)editButtonPressed:(UIBarButtonItem *)sender {
    if (self.editing && self.favoriteCurrencyTable.editing) {
        self.editing = NO;
        [self.favoriteCurrencyTable setEditing:NO animated:YES];
        [self.editButton setTitle:@"Edit"];
    }
    else {
        self.editing = YES;
        [self.favoriteCurrencyTable setEditing:YES animated:YES];
        [self.editButton setTitle:@"Done"];
    }
}

      

+3


source to share


3 answers


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if (([touch.view isKindOfClass:[UIButton class]] && touch.view.tag==<Button_TAG>)) {
        // prevent recognizing touches on the slider
        return NO;
    }
    return YES;
}

      



For touch gestures, add a delegate and write the above code.

+1


source


You need to implement the following method:



- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
    } 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
    }   
}

      

+1


source


If the delete does not work, then it is a problem with the delegate

table view or methods you are calling datasource

Check that these methods must be called

1. tableView:editingStyleForRowAtIndexPath:

2. tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:

3.tableView:shouldIndentWhileEditingRowAtIndexPath:

You are trying to check titleforDeleteConfirmationbutton

if titleforDeleteConfirmationbutton

each time the Edit button is clicked, how many times it calls, and also check shouldIndentwhileediting

if you return the indentation value as yes in the method shouldIndentwhileediting

.

check your gesture recognizers.

0


source







All Articles