MortimerGoro / MGSwipeTableCell

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
MIT License
6.96k stars 1.07k forks source link

Crash on ios 8.3 - unrecognized selector sent to instance #111

Open zakiharis opened 9 years ago

zakiharis commented 9 years ago

I just test this library today and it crash when I'm navigate to the view.

This error -> *\ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell setDelegate:]: unrecognized selector sent to instance

My code as below:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SectionNotifications";
    MGSwipeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSDictionary *dictionary = self.notificationData[indexPath.section];
    NSArray *array = dictionary[@"notifications"];

    MyNotification *n = [array objectAtIndex:indexPath.row];

    UILabel *notificationTitle = (UILabel *)[cell viewWithTag:33302];
    notificationTitle.text = n.notificationTitle;

    cell.delegate = self;
    cell.leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"notification_delete.png"] backgroundColor:[UIColor colorWithHexString:@"#99cbed"]]];
    cell.leftSwipeSettings.transition = MGSwipeTransitionBorder;

    return cell;
}

-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion
{
    NSLog(@"Delegate: button tapped, %@ position, index %d, from Expansion: %@",
          direction == MGSwipeDirectionLeftToRight ? @"left" : @"right", (int)index, fromExpansion ? @"YES" : @"NO");

    if (direction == MGSwipeDirectionRightToLeft && index == 0) {
        //delete button
        NSIndexPath * path = [_tableView indexPathForCell:cell];
        //[tests removeObjectAtIndex:path.row];
        [_tableView deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationLeft];
        return NO; //Don't autohide to improve delete expansion animation
    }

    return YES;
}

Did I miss something?

MortimerGoro commented 9 years ago

mmm It seem's that dequeueReusableCellWithIdentifier:CellIdentifier is returning a not nill cell which is not a MGSwipeTableCell, so it doesn't have the delegate property and crashes.

This can happen if you have registered a class for the same identifier (using registerClass:forCellReuseIdentifier:) or if you are loading the table from a nib/storyboard.

zakiharis commented 9 years ago

yes I'm loading my table from storyboard. (prototype cell)