2013-05-15 143 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

相關問題