7

Cell doesn't allows to delete it. When swipe happens, it slides back, so it's unable to delete it. Message in console says:

attempting to set a swipe to delete cell when we already have one....
that doesn't seem good

Code:

#import "GroupDetailInfoViewController.h"
#import "YFJLeftSwipeDeleteTableView.h"

@interface GroupDetailInfoViewController ()

{
    NSMutableArray * _dataArray;
    UIButton * _deleteButton;
    NSIndexPath * _editingIndexPath;

    UISwipeGestureRecognizer * _leftGestureRecognizer;
    UISwipeGestureRecognizer * _rightGestureRecognizer;
    UITapGestureRecognizer * _tapGestureRecognizer;
}

@property (nonatomic, retain) YFJLeftSwipeDeleteTableView *tableView;
@end


@implementation GroupDetailInfoViewController

- (id)init
{
    self = [super init];
    if (self) {
        // Custom initialization
        _dataArray = [@[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)] mutableCopy];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    CGRect frame = self.view.bounds;
    self.tableView = [[YFJLeftSwipeDeleteTableView alloc] initWithFrame:frame];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    [self.view addSubview:self.tableView];


}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"Data at Row %@", _dataArray[indexPath.row]];

    return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [_dataArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

}

- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"willBeginEditingRowAtIndexPath");
    //[super setEditing:YES animated:YES];
    [self.tableView setEditing:YES animated:YES];

    //Self.editing handles the done / edit button
    tableView.editing = YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCellEditingStyle editingStyle = UITableViewCellEditingStyleNone;
    /*if (tableView.editing)*/ editingStyle = UITableViewCellEditingStyleDelete;

    return editingStyle;
}

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"didEndEditingRowAtIndexPath");
    //[super setEditing:NO animated:YES];
    [self.tableView setEditing:NO animated:YES];

    //Self.editing handles the done / edit button
    tableView.editing = NO;


}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

@end
Shmidt
  • 16,436
  • 18
  • 88
  • 136
Retro
  • 3,985
  • 2
  • 17
  • 41
  • So what's not working exactly? Is the delete button not showing up when you swipe the cell? Or is the delete button not removing the cell? or? – valheru Jan 04 '14 at 19:23
  • delete button not showing up when swipe, actually i have a swipe controller and that is also have gesture recogniser, it seems they are conflicting – Retro Jan 06 '14 at 05:13
  • I don't think it's correct to set the editing property of the table view to YES from within tableView:willBeginEditingRowAtIndexPath:. The table view should already set its editing state to YES when the cell's internal scroll view is swiped. What happens when you comment out all the code that modifies the table view's editing property? – jamesmoschou Feb 10 '14 at 02:51

3 Answers3

3

I had the same problem after adding SWTableViewCell. I added SWTableViewCell after I'd already implemented - (void)tableView:(UITableView)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath*.

Once i'd removed this method, things worked as expected. I guess the view that SWTableViewCell installs conflicts with the system trying to install the same kind of view based on this method.

Karsten
  • 2,772
  • 17
  • 22
1

I had the same error message when I set a timer and was reloading the tableView every time the timer fired (in my case this was once every second). After I removed the timer when I was editing, I stopped getting the error.

stu
  • 11
  • 1
0

Like Karsten, I had the same issue and removing the system method commitEditingStyle:forRowAtIndexPath fixed it. However it now prevents using the system Accessibility actions menu to allow deletion via the accessibility tools.

I've added an issue on the SWTableViewCell github and hopefully they can come up with a fix.

staticnz
  • 491
  • 1
  • 5
  • 15