Tir*_*rth 8 iphone uitableview ios
是的,关于类似问题的堆栈溢出有很多问题.我读了所有这些,但我从来没有看到我的问题等同于他们.现在我的问题是,如果我在第0部分点击headerview更新表格部分0有3行,然后再次点击相同的标题删除0部分中的所有3行,这对我来说很好.但是,如果我打开(更新第3部分有3行),然后我点击另一个标题部分(我要打开的另一部分,然后在第0部分后)我的应用程序崩溃了.我的意思是我想如果我点击其他部分然后我的其他部分应该打开,之前的开放部分应该必须关闭.看到我的代码插入和删除部分和行,
-(void)sectionHeaderView:(TableHeaderView*)sectionHeaderView sectionOpened:(NSInteger)section{
self.sectionOpen = YES;
//Create an array containing data of rows and section which to be inserted in tableView.
NSMutableArray *dataInsertArray = [NSMutableArray arrayWithArray:[self.tableDataSourceDictionary objectForKey: [self.sortedKeys objectAtIndex:section]]];
NSInteger countOfRowsToInsert = [dataInsertArray count];
NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
[indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
[self.tableContents setObject:dataInsertArray forKey:[self.sortedKeys objectAtIndex:section]];
//Create an array containing data of rows and section which to be delete from tableView.
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
NSInteger previousOpenSectionIndex = self.openSectionIndex;
if (previousOpenSectionIndex != NSNotFound ) {
self.sectionOpen = NO;
[previousTableHeader toggleOpenWithUserAction:NO];
NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];
for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
}
[self.tableContents removeObjectForKey:[self.sortedKeys objectAtIndex:previousOpenSectionIndex]];
}
// Apply the updates.
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
self.openSectionIndex = section;
self.previousTableHeader = sectionHeaderView;
}
Run Code Online (Sandbox Code Playgroud)
和我的数据源方法,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
NSInteger numberOfSection = [self.sortedKeys count];
return numberOfSection;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *listData =[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]];
NSInteger numberOfRows = [listData count];
return numberOfRows;
}
Run Code Online (Sandbox Code Playgroud)
我的崩溃报告, Assertion失败 - [UITableView _endCellAnimationsWithContext:],/ SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1070 2013-02-18 11:44:49.343 ManageId [1029:c07]由于未捕获的异常而终止应用程序'NSInternalInconsistencyException',原因:'无效更新:第0节中的行数无效.更新后的现有部分中包含的行数(0)必须等于更新前该部分中包含的行数(3)加上或减去从该部分插入或删除的行数(0插入,1删除)和加或减移入或移出该部分的行数(0移入,0移出).
简单地假设我的2个部分包含3到3行然后它将工作文件但是如果2个部分包含3 - 2行然后它崩溃.我想切换两个部分点击更新部分的标题,这些部分中的行数不一致.
比
小智 4
我发现请将\xc2\xa0your code 中的代码替换为该代码。您必须删除旧索引的数据,而不是当前索引的数据...\n注释行是您的,请检查...
\n\nif (previousOpenSectionIndex != NSNotFound){\n\xc2\xa0self.sectionOpen = NO; \n [previousTableHeader toggleOpenWithUserAction:NO];\n\n//NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];\nNSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] count];\xc2\xa0 \xc2\xa0\n\nfor (NSInteger i = 0; i < countOfRowsToDelete; i++) {\n[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];\n\xc2\xa0}\n\n[[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] removeAllObjects]; \n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
6036 次 |
| 最近记录: |