2013-05-15 147 views
0

我正在使用UISplitViewController创建一个小型的ipad应用程序,它有一个UIMasterViewController和一个​​。我已经删除了UITableView附带的UIMasterViewController,我创建了我自己的UITableView,从Xcode Objects面板中拖放一个。我曾想成功地用数据填充UITableView,但是当我尝试删除单元格或记录时,我似乎得到了“线程1:信号SIGABRT”错误。删除UITableView单元格

下面是我的编辑按钮代码。 (这是一个自定义按钮):

//Edit Button 
int cnt = 0; 
- (IBAction)buttonEditPressed:(id)sender { 

    if (cnt == 0){ 
    [self.myTableView setEditing:YES animated:YES]; 
    _buttonEdit.title = @"Done"; 
     cnt++; 
    } 
    else if (cnt == 1){ 
     [self.myTableView setEditing:NO animated:YES]; 
     _buttonEdit.title = @"Edit"; 
     cnt--; 
    } 

} 

而下面的代码是在删除应该发生(但给我的错误回报代替):

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(editingStyle == UITableViewCellEditingStyleDelete){ 

     [self.moduleTitleStack removeObjectAtIndex:indexPath.row]; 
     [self.myTableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    [self.myTableView reloadData]; 

} 

[更新] numberOfRowsInSection实现:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    //id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section]; 
    //return [sectionInfo numberOfObjects]; 
    return [_numberOfRows count]; 
} 

我会认为这会做这项工作,但不知道为什么我得到这个错误。

+0

你得到的错误是什么? – Ismael

+0

另外,你可以添加你的'numberOfRowsInSection:'实现吗? – Ismael

+0

@Ismael错误不是很清楚,它只是说线程1:信号SIGABRT(请参阅numberOfRowsInSection的更新:) – Led

回答

0

对于答案:

你不需要做[tableView reloadData];如果你只是删除了该行并没有其他变化。

此外,您正在收到的崩溃是您正在删除self.moduleTitleStack中的一个对象,但行数正在检查_numberOfRows。 (我猜他们是不同的数组),这就是你遇到的问题。您需要更新_numberOfRows以反映表视图

一般尖更多地了解你所得到的例外的新格局:

转到左边的断点面板,并在左下方,请点击Add>Exception Breakpoint,然后点击确定。调试器会在抛出异常时停止,给你一些关于异常的信息,以及它发生的地方和发生的确切栈跟踪。

+0

好的,我会尝试的 – Led

+0

感谢您的建议, – Led

相关问题