I'm working with UICollectionView
using PSTCollectionView
Library. I've to create a grid where user can select and deselect
images by tapping on UICollectionViewCell
. I've to show checkBox like
image if cell is selected. And uncheckedBox image if cell is
deselected. I am able to select cell
and display checkBox image.And
also can deselect. But when I select next cell
, the previous deselected
cell
also get selected and shows checkBox image. This is the method I declared in UICollectionViewCell
subClass
-(void)applySelection{
if(_isSelected){
_isSelected=FALSE;
self.contentView.backgroundColor=[UIColor whiteColor];
self.selectImage.image=[UIImage imageNamed:@"unchecked_edit_image.png"];
}else{
_isSelected=TRUE;
self.contentView.backgroundColor=[UIColor whiteColor];
self.selectImage.image=[UIImage imageNamed:@"checked_edit_image.png"];
}
}
And here is my code for didSelectItemAtIndexPath
and
didDeselectItemAtIndexPath
- (void)collectionView:(PSTCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelect method called");
FriendImageCell *cell = (FriendImageCell*)[imageGrid cellForItemAtIndexPath:indexPath];
[selectedImages addObject:[[list objectAtIndex:indexPath.item] objectForKey:@"thumbnail_path_150_150"]];
[cell applySelection];
}
- (void)collectionView:(PSTCollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"did deselect called");
FriendImageCell *cell = (FriendImageCell*)[imageGrid cellForItemAtIndexPath:indexPath];
[selectedImages removeObjectAtIndex:indexPath.item];
[cell setSelected:NO];
[cell applySelection];
}
Can anyone please make me understand whats wrong with my code ? Make me correct if I'm doing anything wrong. Tried many answers on stack-overflow but nothing worked. Any help would be appreciated. Thanks in advance.