2011-11-29 86 views
0

我有一個帶有獎品列表的NSMutableArray。從Array和UITableView中刪除對象

用這些,我填充了一個UITableView。

現在,我正嘗試使用TableView CommitEditingStyle刪除其中的一個獎品。並給我「無效的更新:無效的部分....」錯誤。

我在互聯網上發佈了很多關於「無效更新:無效數量的部分....」的帖子,但是我無法使其工作。

首先我從數組中刪除對象,然後更新TableView(就像所有的帖子教我)。但仍然給我的錯誤

我嘗試設置數組爲nill,是相同的。

是否需要刷新數組或類似的東西?

這是我的代碼:

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


if (editingStyle == UITableViewCellEditingStyleDelete) 
{ 
    [[self myPrizesList] removeObjectAtIndex: [indexPath row]]; 

    [self.tableView beginUpdates];    

    // Either delete some rows within a section (leaving at least one) or the entire section. 
    if ([[self myPrizesList] count] > 0) 
    { 
     // Section is not yet empty, so delete only the current row. 
     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
         withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else 
    { 
     // Section is now completely empty, so delete the entire section. 
     [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] 
       withRowAnimation:UITableViewRowAnimationFade]; 
    } 

    [self.tableView endUpdates]; 
} 

}

我總是說,對於5元件陣列,「包含在更新後的表視圖部分的數目(5)必須等於更新前的表格視圖中包含的觀察值數目(5),加或減插入或刪除的區段數(0插入,1刪除)「

如果我將數組設置爲零,請說: 「更新(1)後表格視圖中包含的部分數量必須爲b È等於包含在表視圖esctions的更新(1)前的數,加或減插入部的數量或刪除(0插入,1刪除)」

感謝和對不起,我的英文不好

+0

請發佈更多的代碼,如果你可以在整個班級 –

+1

請包括你的numberOfSections和numberOfRowsInSection方法,這是它們之間的斷開和你在上面引起你的問題的方法中所做的操作。 – jrturton

+1

@owengerig - 不是全班同學,不! – jrturton

回答

1

這是刪除部分的問題,你正在刪除最終的獎品和部分,但是當表格重新加載時它仍然有原始數量的部分...... 5.你如何確定要返回的部分的數量?如果你刪除了一個,這需要減少。

+0

我認爲這將是問題。 1起來(好像你需要點數)。你應該使用[tableArray count]標記,或者任何你的數組的名字 –