2010-01-08 76 views
2

我使用的iPhone SDKObjective-C和 我得到这个错误信息:重新加载段索引时出现奇怪的错误?

断言失败 - [UITableView的_endCellAnimationsWithContext:],/SourceCache/UIKit/UIKit-984.38/UITableView.m:774 2010- 01-08 13:24:16.842 MyAPP [628:20b]由于未捕获异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第1节中的行数无效。更新后现有节中包含的行数(1)必须等于更新之前该部分中包含的行数(0),加上或减去从该部分插入或删除的行数(0插入,0删除)。

这里是我的代码扩展部分:

- (void)checkAction:(id)sender 
{ 
    //The button is added as subview on a view and the view is section header custom view 
    UIButton *Button = (UIButton*)sender; 
    NSLog(@"Button Tag=%d",Button.tag); 
    if([[self.MySectionIndexArray objectAtIndex:Button.tag] isEqualToString:@"UP"]) 
    { 
     [self.MySectionIndexArray replaceObjectAtIndex:Button.tag withObject:@"DOWN"]; 
     [ButtonDrop setBackgroundImage:[UIImage imageNamed:@"Up.png"] forState:UIControlStateNormal]; 
     [TableDashBoard reloadSections:[NSIndexSet indexSetWithIndex:Button.tag] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else 
    { 
     [self.MySectionIndexArray replaceObjectAtIndex:Button.tag withObject:@"UP"]; 
     [ButtonDrop setBackgroundImage:[UIImage imageNamed:@"Down.png"] forState:UIControlStateNormal]; 
    } 
    NSLog(@"self.MySectionIndexArray ka title = %@ at index Number=%d",self.MySectionIndexArray,Button.tag); 
} 

回答

6

的问题是因为你使用reloadSections同时改变表的dataSource内容,使之通过tableView:numberOfRowsInSection:报告不同的行数。

检查您从UITableViewDataSourcetableView:numberOfRowsInSection:返回的内容。我敢打赌,在开始你的第1节返回0,但是当你调用reloadSections,你为第1

返回1,如果这是真正的情况,你可以使用UITableView方法beginUpdatesinsertRowsAtIndexPaths:withRowAnimation:endUpdates

+0

我不chnaging dataSource.Actually如果我使用reloaddata错误不会来。我使用的是从一个stackoverflow后扩展部分的代码。但我也gettng另一个奇怪的问题here.i已经创建了两个自定义单元格从界面生成器。我想显示分隔符下面的两个单元格,所以我添加一个灰色的标签给他们。现在我的表视图在第一部分我分配一个IB单元格的第一行和另外3行我分配另一个IB单元格。其余的部分alloc默认cells.But当我向下滚动灰色标签转换为白色你是否有任何相关对此? – 2010-01-08 12:28:10

+0

我的意思是你要改变'dataSource'的*内容* - 即你从'tableView:numberOfRowsInSection:'返回的内容 - 这是你所拥有的错误信息直接表示的。 – 2010-01-08 12:31:48

+1

顺便说一句,'reloadData'工作的事实表明我们正在尝试查看'tableView:numberOfRowsInSection:'返回的内容。这是因为调用'reloadSections''会导致表视图向其数据源请求指定节的新单元格。表格视图在插入新单元格时会动画插入新单元格,因为它会将旧单元格动画化。而reloadData只是在没有任何动画的情况下重新加载数据,并且“不应该在插入或删除行的方法中调用,特别是在调用beginUpdates和endUpdates所实现的动画块中” – 2010-01-08 12:46:44

2

我有一个类似的问题。我确信正在更新dataSource。

但最后我意识到,我实际上是修改2个部分,但更新dataSource只有一个。

+0

在一个特殊情况下,当链接部分重新加载到KVO时,重新加载一个部分很重要,只有该部分的行数会发生变化。如果发生影响多个部分的行数的事情,那么所有更改的部分都应该传递给'[reloadSections:withRowAnimation]'。 – user3099609 2015-07-28 12:14:05

相关问题