重新加载部分索引时出现奇怪的错误?

发布于 2024-08-17 01:35:50 字数 1527 浏览 5 评论 0原文

我正在使用 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);
}

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花似海 2024-08-24 01:35:50

问题是因为您在更改表的 dataSource 内容时使用 reloadSections,因此它通过 tableView:numberOfRowsInSection: 报告不同的行数>。

检查从 UITableViewDataSource tableView:numberOfRowsInSection: 返回的内容。我敢打赌,一开始你会为第 1 部分返回 0,但是当你调用 reloadSections 时,你会为第 1 部分返回 1。

如果确实是这种情况,你可以使用 UITableView代码>方法beginUpdatesinsertRowsAtIndexPaths:withRowAnimation:endUpdates

The problem is because you're using reloadSections while changing the table's dataSource contents, so that it reports a different number of rows via tableView: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 call reloadSections, you return 1 for section 1.

If this is actually the case, you can use UITableView methods beginUpdates, insertRowsAtIndexPaths:withRowAnimation: and endUpdates.

路弥 2024-08-24 01:35:50

我有类似的问题。我确信正在更新数据源。

但最后我意识到我实际上修改了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文