【问题标题】:didSelectItemAtIndexPath is not getting called when the cell is not loaded completely未完全加载单元格时未调用 didSelectItemAtIndexPath
【发布时间】:2016-03-21 14:00:30
【问题描述】:

我在里面有收藏视图,我正在加载图像(图像有长按手势识别器)。 当集合视图单元未完全加载时,不会调用 didSelectItemAtIndexPath 方法。

我向下滚动并加载所有内容,然后我将该单元格放在一个位置(附加屏幕截图),现在 didSelectItemAtIndexPath 方法被调用

cellForItemAtIndexPath 代码如下:-

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

    modelProductDetails=[self.productsArray objectAtIndex:indexPath.row];

    PLPCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"plpcollectiocellIdentifier" forIndexPath:indexPath];
    [cell.imgview addGestureRecognizer:longPress];



    cell.conlblofferpriceheight.constant=21;
    cell.shareView.alpha = 0;

    double actualPrice = [modelProductDetails.price doubleValue];// striked out
    double offerPrice = [modelProductDetails.final_price doubleValue];//will be in red instead of special price

    cell.lblitemPrice.text = [MyShoppingCartViewController displayFormattedPrice: modelProductDetails.price];


    if (offerPrice < actualPrice && offerPrice != 0) {

        NSMutableAttributedString *priceString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@" ,cell.lblitemPrice.text]];

        [priceString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [priceString length])];

        cell.lblitemofferprice.text = [MyShoppingCartViewController displayFormattedPrice:modelProductDetails.final_price];

        [cell.lblitemPrice  setAttributedText:  priceString];

    }
    else
    {
        [cell.lblitemofferprice setText:nil];
    }


    cell.lblIteeTitle.text=modelProductDetails.brand;
    cell.lblitemDescription.text=modelProductDetails.name;
    cell.lblIteeTitle.text=modelProductDetails.manufacturer_value;

    NSURL *url=[NSURL URLWithString:modelProductDetails.small_image];
    [cell.imgview sd_setImageWithURL:url placeholderImage:nil];


    UILongPressGestureRecognizer *longPressGes = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
    longPressGes.minimumPressDuration = 1.0f;
    longPressGes.allowableMovement = 100.0f;
    [cell.imgview addGestureRecognizer:longPressGes];
    [cell.shareButton setTag:indexPath.row];
    [cell.addToWishlistButton setTag:indexPath.row];
    [cell.shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.addToWishlistButton addTarget:self action:@selector(addToWishlistAction:) forControlEvents:UIControlEventTouchUpInside];
    cell.shareButton.tag=indexPath.row;
    cell.addToWishlistButton.tag=indexPath.row;

    return cell;

}

附加信息:只有右侧的单元格有问题,左侧的单元格工作正常

【问题讨论】:

  • 单元格中有按钮吗?
  • @sourav 单元格内没有按钮
  • @Fogmeister 你想看 cellforitematindexpath 代码
  • 然后检查您的数据源是否正确添加。
  • 任何代码。屏幕截图对于调试代码不工作的原因没有用:)

标签: ios objective-c uitableview


【解决方案1】:

didSelectItemAtIndexPathUICollectioView 的委托方法,请确保正确绑定UICollectionView DatasourceDelegate

【讨论】:

  • 我已添加数据源 n 委托 didSelectItemAtIndexPath 在其他场景中工作....
猜你喜欢
  • 2015-11-13
  • 1970-01-01
  • 2019-05-28
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 2016-02-25
  • 2021-07-29
相关资源
最近更新 更多