2013-02-18 2 views
8

예 비슷한 질문에 스택 오버플로가 너무 많습니다. 나는 그 모든 것을 읽었지 만 나는 그들과 동등한 나의 문제를 보지 못했다. 이제 제 문제는 제가 테이블 섹션 0을 0 번 섹션에서 헤더 뷰를 클릭 할 때 3 번 클릭하고 0 번 섹션에서 3 번 행을 삭제할 때 같은 헤더를 다시 클릭하면 업데이트됩니다. 그러나 내가 열면 (3 행으로 섹션 0 업데이트) 그리고 나서 다른 헤더 섹션 (다른 섹션은 0 번 섹션 이후에 열고 싶다)을 클릭하면 애플리케이션이 다운된다. 나는 다른 섹션을 클릭하면 내 다른 섹션이 열리고 이전 섹션이 닫혀 있어야한다는 것을 의미합니다./SourceCache : [jQuery과 _endCellAnimationsWithContext] - 삽입과 삭제 섹션과 행을의Tableview 업데이트 'NSInternalInconsistencyException', 이유 : '잘못된 업데이트 : 행 수가 잘못되었습니다?

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

그리고 내 데이터 소스 방법,

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

내 충돌 보고서, 어설 션 실패를 내 코드를 볼 /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 행이 포함되어 있으면 충돌합니다. 두 섹션을 전환하려면 해당 섹션의 행 수가 일치하지 않는 섹션의 헤더를 클릭하십시오.

보다

+0

하는 첫번째 행을 삭제 시도하고 최종 업데이트 후 새로운 update.Or에 행을 삽입 reloadData 메서드를 사용하면 데이터 소스 값을 기반으로 행을 자동으로 제거합니다. – fibnochi

+0

@fibnochi, 나는 이미 모든 것을했습니다. 그러나 성공하지 못했습니다. – Tirth

+0

삽입을 시도한 다음 행을 삭제하십시오. 이런 식으로 행 수가 먼저 추가 된 다음 삭제됩니다. – fibnochi

답변

4

코드에서 해당 코드를 해당 코드로 바꾸십시오. 당신이없는 현재와 이전 인덱스 데이터를 삭제해야합니다 .... 주석 라인은 당신이 그것을 확인하시기 바랍니다했다 ...

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]; 
} 
관련 문제