I applied these code in my ViewController A. After clicked UICollectionViewCell, it will push to ViewController B. How can I dismiss highlighted cell if back to ViewController A?
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = ThemeLightGrayColor;
[collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
UPDATED:-
Please find below codes (didselectItemAtIndexPath and cellForItemAtIndexPath) for your reference:-
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0)
{
_productID = [_aryWishlist[indexPath.row]valueForKey:@"product_id"];
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *url_string2 = [NSString stringWithFormat: @"http://api.XXX.com/api/product/product_details/%@",_productID];
NSData *data2 = [NSData dataWithContentsOfURL: [NSURL URLWithString:url_string2]];
productDetailsAry = [NSJSONSerialization JSONObjectWithData:data2 options:kNilOptions error:&error];
});
Product_ViewController *prodVC = [[Product_ViewController alloc] init];
[self.navigationController pushViewController:prodVC animated:YES];
}
else
{
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *gridcell = nil;
if(_aryWishlist.count > 0)
{
WishlistCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:WishlistCellID forIndexPath:indexPath];
[cell.sameButton setTitle:[_aryWishlist [indexPath.row]valueForKey:@"condition"] forState:UIControlStateNormal];
if([[_aryWishlist[indexPath.row]valueForKey:@"price_discount"] isEqual:@""]){ //No Price Discount
}
cell.removeWishlistClick = ^{
NSString *url_string = [NSString stringWithFormat: @"http://api.XXX.com/api/product/wishlist_delete/%@",[_aryWishlist [indexPath.row]valueForKey:@"user_wishlist_id"]];
[self.manager DELETE:url_string parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
[self.collectionView reloadData];
[self viewDidLoad];
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
}];
};
}
gridcell = cell;
}