重新加载部分索引时出现奇怪的错误?
我正在使用 iPhone SDK 和 Objective-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);
}
I am using the iPhone SDK and Objective-C and
I get this error message:
Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:774
2010-01-08 13:24:16.842 MyAPP[628:20b] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).
Here is my code to expand sections:
- (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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是因为您在更改表的
dataSource
内容时使用reloadSections
,因此它通过tableView:numberOfRowsInSection:
报告不同的行数>。检查从
UITableViewDataSource
tableView:numberOfRowsInSection:
返回的内容。我敢打赌,一开始你会为第 1 部分返回 0,但是当你调用reloadSections
时,你会为第 1 部分返回 1。如果确实是这种情况,你可以使用
UITableView
代码>方法beginUpdates
、insertRowsAtIndexPaths:withRowAnimation:
和endUpdates
。The problem is because you're using
reloadSections
while changing the table'sdataSource
contents, so that it reports a different number of rows viatableView:numberOfRowsInSection:
.Check what you return from your
UITableViewDataSource
tableView:numberOfRowsInSection:
. My bet is that at the beginning you return 0 for section 1, but when you callreloadSections
, you return 1 for section 1.If this is actually the case, you can use
UITableView
methodsbeginUpdates
,insertRowsAtIndexPaths:withRowAnimation:
andendUpdates
.我有类似的问题。我确信正在更新数据源。
但最后我意识到我实际上修改了 2 个部分,但只更新了其中一个的数据源。
I had a similar problem. I was sure of being updating the dataSource.
But finally I realized that I was actually modifying 2 sections but updating the dataSource for only one.