2011-11-29 83 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]标记,或者任何你的数组的名字 –