2011-04-05 76 views
0

我想从我的表视图中删除单元格,但它显示例外:异常而删除细胞

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

这里是我的代码:

 
- (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]; 
    } 

控制显示在印刷后的8号线除外“删除”一词。也给出了警告,“根视图控制器不响应aBook” 帮助!

回答

1

也许你的意思

[aBook removeObjectAtIndex:[indexPath row]]; 
+0

不工作仍然给予相同的例外! – Ketan 2011-04-05 12:28:27

1

你为什么叫[自我ABOOK]?这是本地对象!尝试[aBook removeObjectAtIndex:]

+0

仍然给我同样的例外,当我使用aBook removeObjectAtIndex:[indexPath row]]; – Ketan 2011-04-05 12:28:03

1

运行时已经为您提供了一个非常好的解释错误的方法:您正在向RootViewController(实现发布代码的类)的对象发送aBook消息。

因此,[self aBook]无效。

另外,接受更多答案。

+0

好!我试过的代码行:aBook removeObjectAtIndex:[indexPath row]];由其他开发者建议,但仍然给出相同的错误! – Ketan 2011-04-05 12:31:59

+0

@ketan这不太可能。 – 2011-04-05 12:40:03

+0

它也发出警告“图书可能无法响应removeobjectatindex”。我必须犯错,但我无法追查。 – Ketan 2011-04-05 12:46:49