Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Tableview更新';n内部一致性异常';,原因:';无效更新:行数无效?_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone Tableview更新';n内部一致性异常';,原因:';无效更新:行数无效?

Iphone Tableview更新';n内部一致性异常';,原因:';无效更新:行数无效?,iphone,ios,uitableview,Iphone,Ios,Uitableview,是的,在类似的问题标题上,有很多关于堆栈溢出的问题。我读了所有这些,但我从来没有看到我的问题相当于他们。 现在我的问题是,如果我在单击节0上的headerview时更新表节0有3行,然后再次单击相同的标题以删除节0中的所有3行,这对我来说很好。但如果我打开(用3行更新节0),然后单击另一个标题节(另一个我想打开的节,然后在第0节之后),我的应用程序就会崩溃。我的意思是,如果我点击了其他部分,那么我的其他部分应该已经打开,而之前打开的部分应该已经关闭。有关插入和删除节和行的信息,请参见我的代码

是的,在类似的问题标题上,有很多关于堆栈溢出的问题。我读了所有这些,但我从来没有看到我的问题相当于他们。 现在我的问题是,如果我在单击节0上的headerview时更新表节0有3行,然后再次单击相同的标题以删除节0中的所有3行,这对我来说很好。但如果我打开(用3行更新节0),然后单击另一个标题节(另一个我想打开的节,然后在第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;
}
我的事故报告, 在-[UITableView\u endCellAnimationsWithContext:],/SourceCache/UIKit\u 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行,那么它将崩溃。我想切换两个部分,单击更新这些部分中行数不一致的部分标题


然后,我发现请用该代码替换代码中的代码。您必须使用旧索引而不是当前索引删除数据。。。。 评论行是您的,请检查

if (previousOpenSectionIndex != NSNotFound){
 self.sectionOpen = NO; 
 [previousTableHeader toggleOpenWithUserAction:NO];

//NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];
NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] count];   

for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
 }

[[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] removeAllObjects];  
}
if(以前的OpenSectionIndex!=NSNotFound){
self.sectionOpen=否;
[previousTableHeader toggleOpenWithUserAction:否];
//NSInteger countOfRowsToDelete=[[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:section]]count];
NSInteger countOfRowsToDelete=[[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:previousOpenSectionIndex]]count]
对于(NSInteger i=0;i
尝试先删除行,然后结束更新,然后使用新的更新插入行。或者使用重新加载数据方法,它将根据数据源值自动添加或删除行。@fibnochi,我已经做了所有的方法。但没有成功。请尝试插入,然后删除行。通过这种方式,将先添加行数,然后删除行数。再尝试一次不带动画的更新。
if (previousOpenSectionIndex != NSNotFound){
 self.sectionOpen = NO; 
 [previousTableHeader toggleOpenWithUserAction:NO];

//NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];
NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] count];   

for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
 }

[[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] removeAllObjects];  
}