iosobjective-cuitablevieweditmode

Deletion control button on UITableview edit mode is not working


I have implemented UITableview edit mode when a button is clicked but every time it goes to edit mode and I click on the deletion button, nothing happens. I have a view controller with a UITableview on it. I have set my delegate and tableview source as well as all of my editing callbacks. Everything is working (like reordering cells) but whenever I try to delete by pressing the delete control button, the delete button doesn't show up.

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

This is how I am implementing 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"];
    }
}

Solution

  • - (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 tap gestures add the delegate and write the above code.