0
votes

i am trying to delete a cell from my table view but it's displaying exception:

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[RootViewController aBook]: unrecognized selector sent to instance 0x3d217a0'

here is my code:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {  
        NSLog(@"handover values to object");
        Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
        NSLog(@"removing");
        [[self aBook] removeObjectAtIndex:[indexPath row]];
        NSLog(@"deleting row");
        //  Animate deletion
        NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
        [[self tableView] deleteRowsAtIndexPaths:indexPaths
                                withRowAnimation:UITableViewRowAnimationFade];
    }

control displays exception at 8th line after printing "removing" word. also giving warning that "root view controller not responding to aBook" help!!

3

3 Answers

1
votes

Why are you calling [self aBook]? It's local object! Try [aBook removeObjectAtIndex: ]

1
votes

The runtime already gives you a very good explanation of what's wrong: You are sending a aBook message to an object of type RootViewController (the class in which you implemented the posted code).

So, [self aBook] is not valid.

Also, accept more answers.

1
votes

perhaps you mean

[aBook removeObjectAtIndex:[indexPath row]];