I m using collectionCell
to select and deselect image on collectionCell
. But when i click on selected cell , it wont get deselected.
I changed my Code as per as Nirav Suggestion and it working for current View but when i m coming from another view by passing some object then those object should be marked checked. If i click on mark objects that is selected it does not deselect the cell.
My Code
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BICollectionCell *cell = (BICollectionCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:@"BICollectionCell" forIndexPath:indexPath];
CustVehiclesList *objCustVehiclesList =self.array_VehicleServicesList[indexPath.row];
[cell.labelMake setText:objCustVehiclesList.make];
[cell.lblLicense setText:objCustVehiclesList.licencePlateNo];
if (objCustVehiclesList.vehiclePicture == nil ||[objCustVehiclesList.vehiclePicture isEqualToString:@""])
{
[cell.imageCarsView setImage:[UIImage imageNamed:@"placeholder.png"]];
}
else
{
NSString *baseString = [NSString stringWithFormat:@"%@",objCustVehiclesList.vehiclePicture];
NSData* imageData = [[NSData alloc] initWithBase64EncodedString:baseString options:0];
UIImage *imageToDisplay = [UIImage imageWithData:imageData];
[cell.imageCarsView setImage:imageToDisplay];
}
[cell setSelected:YES];
[self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
if (self.selectedIndexPath == indexPath)
{
[cell.imgSelectedImage setImage:[UIImage imageNamed:@"vs_tick.png"]];
}
else
{
[cell.imgSelectedImage setImage:nil];
}
if ([objCustVehiclesList.modelName isEqualToString:self.str_ModelName] && _isCalledFromDetailVC)
{
[cell.imgSelectedImage setImage:[UIImage imageNamed:@"vs_tick.png"]];
}
if (indexPath.row == self.indexPathToBeSearch.row && self.isCalledFromVehicleVC)
{
[cell.imgSelectedImage setImage:[UIImage imageNamed:@"vs_tick.png"]];
}
return cell;
}