2013-10-07 8 views
1

10 개의 섹션을 포함하고 각 섹션에 2 개의 셀이있는 UICollectionView가 있습니다. 나는 셀을 삭제하려고하지만 난이 점점 오전 :업데이트 후에 컬렉션보기에 포함 된 섹션 수는 업데이트 전과 같아야합니다.

The number of sections contained in the collection view after the update (2) must be equal to the number of sections contained in the collection view before the update (2) 

이 내가 제거하는 방법입니다

NSUInteger arrayLength = 1; 
    NSUInteger integerArray[] = {0,0}; 
    NSIndexPath *aPath = [[NSIndexPath alloc] initWithIndexes:integerArray length:arrayLength]; 
    [self.collectionFavs deleteItemsAtIndexPaths:[NSArray arrayWithObject:aPath]]; 

난 그냥 셀과 셀 또는 섹션을 삭제할. 내 실수는 무엇입니까?

답변

1

데이터 소스 배열에서 요소를 삭제해야합니다. F.e. 이 방법에 [배열 개수]를 반환하는 경우 삭제 한 후 다음 셀을 삭제하기 전에 당신의 방법 수익이 그것이 사실 일

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    if (notdeleted) 
     return 2; 
    else 
     return 1; 
} 

을 반환해야하는 경우에, 당신은 전화 -deleteItemsAtIndexPaths 전에 배열에서 1 개체를 제거해야

NSUInteger integerArray[] = {0,0}; 
NSIndexPath *aPath = [[NSIndexPath alloc] initWithIndexes:integerArray length:arrayLength]; 
[array removeObjectAtIndex:0]; 
[self.collectionFavs deleteItemsAtIndexPaths:[NSArray arrayWithObject:aPath]]; 
+0

이제 작동 중입니다 ... 대단히 감사합니다. 그러나 이것은 섹션을 제거하기 때문에 섹션 내부의 셀만 제거 할 수 있습니까? – onivi

+0

이상하게 보입니다. 데이터 소스 프로토콜에는 두 가지 메소드가 있습니다. - collectionView : numberOfItemsInSection : and - numberOfSectionsInCollectionView :. 먼저 일부 섹션에서 설정된 셀 수에 사용되며, 섹션 수가 설정된 경우 두 번째로 필요합니다. 어쩌면 잘못된 배열에서 객체를 제거 할 수 있습니까? :) – Josshad

+0

10 개의 섹션이 있고 각 섹션에는 2 개의 셀이 있습니다. 개별적으로 각 셀을 제거하려고하지만 모든 셀이 섹션에서 제거되면이 섹션도 제거하려고합니다. – onivi

관련 문제