Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Objective c collectionView拾取错误的数据_Objective C_Uicollectionviewcell - Fatal编程技术网

Objective c collectionView拾取错误的数据

Objective c collectionView拾取错误的数据,objective-c,uicollectionviewcell,Objective C,Uicollectionviewcell,我使用的UICollectionViewCell子类有两个按钮“添加到购物车”和“删除”。我已经为在已经添加到购物车的单元格上显示remove进行了编程,但是collectionView只更改最后添加的产品的标题。我认为重复使用电池会有一些问题 这是我的手机号码 - (ShoppingCellCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexP

我使用的UICollectionViewCell子类有两个按钮“添加到购物车”和“删除”。我已经为在已经添加到购物车的单元格上显示remove进行了编程,但是collectionView只更改最后添加的产品的标题。我认为重复使用电池会有一些问题

这是我的手机号码

- (ShoppingCellCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    ShoppingCellCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShoppingViewCell" forIndexPath:indexPath];

     NSString *imgURLSTR = [NSString stringWithFormat:@"%@%@",IMAGE_BASEURL,[[[data valueForKey:@"products"] valueForKey:@"imagepath"] objectAtIndex:indexPath.row]];
    imgURLSTR = [imgURLSTR stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    [cell.itemImageView sd_setImageWithURL:[NSURL URLWithString:imgURLSTR] placeholderImage:[UIImage imageNamed:@"telebuy_logo.png"]];

    [cell.itemTitle setText:[NSString stringWithFormat:@"%@",[[[data valueForKey:@"products"] valueForKey:@"desc"] objectAtIndex:indexPath.row]]];
    [cell.rateLabel setText:[NSString stringWithFormat:@"INR %@",[[[data valueForKey:@"products"] valueForKey:@"salevalue"] objectAtIndex:indexPath.row]]];

    [cell.featureButtonOutlet addTarget:self action:@selector(featuresBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [cell.featureButtonOutlet setTag:indexPath.row];

    NSDictionary*dict = [[data valueForKey:@"products"]objectAtIndex:indexPath.item];
    NSString* singleProductFromAllProducts = [dict valueForKey:@"id"];

    for (int i = 0 ; i<dataC.count; i++) {

        if ([singleProductFromAllProducts isEqualToString:[[dataC objectAtIndex:i]valueForKey:@"prodid"]]) {

            NSLog(@"Item is %@",[[dataC objectAtIndex:i]valueForKey:@"prodid"]);
            NSLog(@"%@",singleProductFromAllProducts);

            [cell.addToCartButtonOutlet setTitle:@"Remove" forState:UIControlStateNormal];
            cell.addToCartButtonOutlet.backgroundColor = [UIColor grayColor];

        }
        else
        {
            [cell.addToCartButtonOutlet setTitle:@"Add To Cart" forState:UIControlStateNormal];
            cell.addToCartButtonOutlet.backgroundColor = [UIColor redColor];
        }
    }
    [cell.addToCartButtonOutlet addTarget:self action:@selector(addToCartBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [cell.addToCartButtonOutlet setTag:indexPath.row];

    return cell;
}

需要帮助。

您真的没有注意到您的格式已完全关闭?您真的没有注意到您的格式已完全关闭?
#import "ShoppingCellCollectionViewCell.h"
#import "AppDelegate.h"
#import "ShoppingViewController.h"

@implementation ShoppingCellCollectionViewCell

- (void)awakeFromNib {
    // Initialization code

    _itemImageView.layer.borderWidth = 0.5;
    _itemImageView.layer.borderColor = [UIColor lightGrayColor].CGColor;


    [_addToCartButtonOutlet setBackgroundColor:[APPDELEGATE colorFromHexString:@"#035098"]];
    [_addToCartButtonOutlet setBackgroundColor:[APPDELEGATE colorFromHexString:@"#ee1c25"]];
}