Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 单击后如何取消突出显示UICollectionViewCell?_Ios_Objective C_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios 单击后如何取消突出显示UICollectionViewCell?

Ios 单击后如何取消突出显示UICollectionViewCell?,ios,objective-c,uicollectionview,uicollectionviewcell,Ios,Objective C,Uicollectionview,Uicollectionviewcell,我在我的ViewController A中应用了这些代码。单击UICollectionViewCell后,它将推送到ViewController B。如果返回到ViewController A,如何取消突出显示的单元格 - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *c

我在我的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];
}

更新:-

请查找以下代码(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;

        }
Swift 4.1

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    collectionView.deselectItem(at: indexPath, animated: true)
    //perform segue
}

问题是您正在为单元格设置背景色,无论是否选中。如果要在选定单元格时使用自定义背景色,则有两个选项:

1-使用具有所需背景颜色的单元格的自定义视图:

检查

2-覆盖单元格中选定属性的setter

- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];

    if (selected) {
        self.contentView.backgroundColor = ThemeLightGrayColor;
    } else {
        self.contentView.backgroundColor = UIColor.clearColor();
    }
}
并删除:

cell.contentView.backgroundColor = ThemeLightGrayColor;

在viewwillappearHi RajeshKumar中重新加载collectionview,尝试过但没有成功,有什么想法?单击单元格后,您将按Viewcontroller B,然后为什么要设置单元格的背景色?嗨,Nirav,我的预期结果是在用户按下时高亮显示单元格