Я применил этот код в моем ViewController A. После нажатия UICollectionViewCell, он переместится в ViewController B. Как я могу отклонить подсвеченную ячейку, если вернуться к ViewController A?
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = ThemeLightGrayColor;
[collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
![enter image description here](https://i.stack.imgur.com/fWZBP.png)
ОБНОВЛЕНО: -
Ниже приведены коды (didselectItemAtIndexPath и cellForItemAtIndexPath) для справки: -
- (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;
}