gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:49:48 27 4
gpt4 key购买 nike

我正在使用iPhone SDKObjective-C和我收到此错误消息:

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).

这是我扩展部分的代码:

- (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);
}

最佳答案

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

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

如果确实如此,您可以使用 UITableView 方法 beginUpdatesinsertRowsAtIndexPaths:withRowAnimation:endUpdates >.

关于objective-c - 重新加载部分索引时出现奇怪的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2026219/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com