2013-04-24 3 views
1

collection view에 이미지를 표시하고 있습니다. button click에있는 각 항목을 삭제하고 싶습니다. 이제 didSelect method에서 해당 항목을 삭제할 수 있습니다. 그냥UICollectionView에서 항목을 삭제하는 방법은 무엇입니까?

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; 
[self.colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:[indexPath]]]; 
+1

'사용하여 다시 시도 data' 또는'reloadItemsAtIndexPath' –

답변

3

을 삭제하는 방법 indexpath.rowon click 나누었다을 찾을 수 있습니다

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [array removeObjectAtIndex:indexPath.row]; 
    [self.colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; 
} 

arraynumberOfItemsInSection에서 사용되는지 확인하십시오. 그러면 dataSource가 다시로드됩니다.

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return [yourArray count]; 
} 

-(void)chat:(int)i 
{ 
    NSLog(@"index path%d",i); 
    [yourArray removeObjectAtIndex:i]; 
    // array object is getting removed,how to delete the CollectionviewCell 
    [self.collectionView reloadData]; 
} 
+0

하지만 난 한 번 삭제 한 후, 인덱스 경로가 감소 얻을 나던 ..이 자신을 태업하는 –

+0

:'NSLog (@ "인덱스 경로 % d 개" i); 그것은 indexPath가 아닙니다. 가장 좋은 곳은 제거하려는 행 **이있는 곳입니다. 배열의 내부에있는 값에서 행의 값을 하드 코딩하기 때문에 정상입니다. 그 대신 객체의 위치를 ​​가져 와서 인덱스를 얻으십시오 :'[array indexOfObject : theObjectIWantToRemove]; ' – Peres

+0

하지만 콜렉션 뷰를 다시로드 한 후에는 OK입니다. 그러나 삭제 후에 셀 재 배열 애니메이션이 더 이상 없습니다. . –

1

reloadData : 나는 CollectionCell에 버튼을 배치하고 당신은뿐만 아니라 섹션을 알고있는 경우

-(void)chat:(int)i 
{ 
    NSLog(@"index path%d",i); 
    [array removeObjectAtIndex:i]; // array object is getting removed,how to delete the CollectionviewCell 
} 
관련 문제