2014-04-17 2 views
0

apple 설명서를 읽은 후 다음 함수를 사용하여 collectionView의 전체 내용을 삭제하려고합니다.UICollectionView가 새 데이터 세트로 새로 고침

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CreatingCellsandViews/CreatingCellsandViews.html#//apple_ref/doc/uid/TP40-CH7-SW7

그것은 다음과 같은 오류와 함께 종료됩니다.

'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]" 

} 미리

감사하다

+0

모든 컨텐츠를 사용하려는 경우 배열의 모든 데이터를 제거하고 [collectionView reloadData]를 호출하십시오. – Pete42

+0

@ Pete42 예, 나는 그것을 시도했습니다. 그리고 데이터가 없을 때 성공합니다. 새 데이터로 배열을 업데이트하면 EXC_BAD_ACCESS 오류로 끝납니다. 그리고 나는 배열 할당과 관련이 있다고 생각합니다. :-( –

+0

델리게이트 메서드의 섹션 수와 항목 수가 배열에서 액세스하려고 시도하는 내용과 일치하는지 확인해야합니다. 컬렉션 인덱스 함수에서 뷰의 항목이 EXC_BAD_ACCESS를 제공하는 배열의 범위를 벗어나 액세스하려고 시도합니다. – Pete42

답변

0

그것은 당신이 모두 제거하는 것이 보인다 목적 s를 먼저 displayDataArray에서 가져온 다음 indexPathArraydisplayDataArray에서 계산하십시오. 따라서 indexPathArray는 및

[self.galleryCollectionView deleteItemsAtIndexPaths:[self createIndexPathArrayEntireCollectionView]]; 

아무것도하지 않습니다 비어 있습니다. 주문을

[self.galleryCollectionView deleteItemsAtIndexPaths:[self createIndexPathArrayEntireCollectionView]]; 
[displayDataArray removeAllObjects]; 

으로 변경할 수 있습니다. 그러나 댓글에 언급 된대로 reloadData으로 전화하면 모두 컬렉션보기 항목이 제거되었습니다.

+0

위의 사과 설명서에있는 링크도 시도했지만 표시 배열을 변경하고 삭제를 수행하는 방법을 참조합니다 버튼을 클릭하면 collectionView를 업데이트하는 프로그램 샘플을 찾을 수 없습니다. :-( –

+0

@VARUNISAC : performBatchUpdates 블록 내에서 데이터 소스를 변경하거나 컬렉션보기 항목을 먼저 삭제하면 상관 없습니다. 그리고 코드에서 createIndexPathArrayEntireCollectionView가 호출 될 때 displayDataArray는 이미 * 비어 있습니다 * –

+0

문제를 파악할 수 없습니다. 하지만 데이터 소스가 비어있을 때 문제가 발생한다는 것을 알게되면 빈 보이지 않는 셀을 추가하여 오류를 건너 뜁니다. –