apple 설명서를 읽은 후 다음 함수를 사용하여 collectionView의 전체 내용을 삭제하려고합니다.UICollectionView가 새 데이터 세트로 새로 고침
그것은 다음과 같은 오류와 함께 종료됩니다.
'NSInternalInconsistencyException'이라는 캐치되지 않은 예외로 인해 앱이 종료됩니다. 이유 : '잘못된 업데이트 : 섹션 수가 잘못되었습니다. 업데이트 (0) 후 콜렉션 뷰에 포함 된 섹션 수는 업데이트 (5) 이전의 콜렉션 뷰에 포함 된 섹션 수와 같거나 삽입되거나 삭제 된 섹션 수를 더한 값 또는 빼기 값이어야합니다 (0 삽입, 0 삭제됨). '
이것은 무엇을 의미합니까? 또는 버튼을 클릭 할 때 새로운 데이터 세트로 collectionView의 내용을 새로 고치는 방법에 대한 예제와 함께 참조 링크를 보여줄 수 있습니까?
-(void) clearCollectionViewAndDataArray
{
[self.galleryCollectionView performBatchUpdates:^{
[displayDataArray removeAllObjects];
NSLog(@"Is it empty---?%@",displayDataArray);
[self.galleryCollectionView deleteItemsAtIndexPaths:[self createIndexPathArrayEntireCollectionView]];
}
completion:nil ];
}
-(NSMutableArray*) createIndexPathArrayEntireCollectionView
{
NSMutableArray* indexPathArray = [[NSMutableArray alloc] init];
for(int i=0; i < [displayDataArray count]; i++)
{
NSMutableArray* sectionArray=[[NSMutableArray alloc] init];
sectionArray=[displayDataArray objectAtIndex:i];
for(int j=0; j < [sectionArray count]; j++)
{
NSIndexPath* newPath = [NSIndexPath indexPathForRow:j inSection:i];
[indexPathArray addObject: newPath];
}
}
return indexPathArray;
}
사용되는 NSMutableArray의 데이터
은 다음과 같습니다 이(
(
"<SACatalogs: 0x9554750>",
"<SACatalogs: 0x953d9c0>",
"<SACatalogs: 0x953e050>"
),
(
"<SACatalogs: 0x953e6e0>",
"<SACatalogs: 0x953ed70>",
"<SACatalogs: 0x953f420>"
),
(
"<SACatalogs: 0x953fab0>",
"<SACatalogs: 0x9540160>",
"<SACatalogs: 0x95407f0>"
),
(
"<SACatalogs: 0x9540ec0>",
"<SACatalogs: 0x9541530>",
"<SACatalogs: 0x9541be0>"
),
(
"<SACatalogs: 0x9542290>",
"<SACatalogs: 0x9542940>",
"<SACatalogs: 0x9542ff0>"
)
)
사용되는 인덱스 경로
"<NSIndexPath 0xa6bb9a0> 2 indexes [0, 0]",
"<NSIndexPath 0xa648bc0> 2 indexes [0, 1]",
"<NSIndexPath 0xa6dcdc0> 2 indexes [0, 2]",
"<NSIndexPath 0xa6c7d00> 2 indexes [1, 0]",
"<NSIndexPath 0xa6c91c0> 2 indexes [1, 1]",
"<NSIndexPath 0xa6f6100> 2 indexes [1, 2]",
"<NSIndexPath 0xa6490d0> 2 indexes [2, 0]",
"<NSIndexPath 0xa6a93b0> 2 indexes [2, 1]",
"<NSIndexPath 0xa6d08b0> 2 indexes [2, 2]",
"<NSIndexPath 0xa64ddb0> 2 indexes [3, 0]",
"<NSIndexPath 0xa6f7380> 2 indexes [3, 1]",
"<NSIndexPath 0xa6c1c90> 2 indexes [3, 2]",
"<NSIndexPath 0xa6e45f0> 2 indexes [4, 0]",
"<NSIndexPath 0xa6bf840> 2 indexes [4, 1]",
"<NSIndexPath 0xa6a03f0> 2 indexes [4, 2]"
} 미리
감사하다
모든 컨텐츠를 사용하려는 경우 배열의 모든 데이터를 제거하고 [collectionView reloadData]를 호출하십시오. – Pete42
@ Pete42 예, 나는 그것을 시도했습니다. 그리고 데이터가 없을 때 성공합니다. 새 데이터로 배열을 업데이트하면 EXC_BAD_ACCESS 오류로 끝납니다. 그리고 나는 배열 할당과 관련이 있다고 생각합니다. :-( –
델리게이트 메서드의 섹션 수와 항목 수가 배열에서 액세스하려고 시도하는 내용과 일치하는지 확인해야합니다. 컬렉션 인덱스 함수에서 뷰의 항목이 EXC_BAD_ACCESS를 제공하는 배열의 범위를 벗어나 액세스하려고 시도합니다. – Pete42