2

私はuicollectionviewセルにデータを設定して選択を解除しますが、すべてが完璧に動作しますが、いつかスクロールを開始すると、以下はコードです、助けていただければ幸いです。UICollectionviewはスクロール時に選択の選択/無効を切り替える - iOS

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

     cell = (BYOCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"CVCCell" forIndexPath:indexPath]; 
     cell.vSelectionView.hidden = YES; 
     cell.vSelectionView.backgroundColor = customLightGreenColor; 
     [self makeRoundElement:cell.vSelectionView forLabel:nil withCorner:8.0f withBorder:0]; 

     pizzaInfo *pizzainfo= [[pizzaInfo alloc]init]; 
     pizzainfo = [_lstDishCollection objectAtIndex: indexPath.row]; 
     if (pizzainfo._bIsSelected) 
     { 
      cell.vSelectionView.hidden = NO; 
     } 
     else 
     { 
      cell.vSelectionView.hidden = YES; 
     } 
     //label customization 
     return cell; 
} 

DidselectItemcollectionViewCellオーバー

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
     cell = (BYOCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"CVCCell" forIndexPath:indexPath]; 
     pizzaInfo *pizzaInfoCellData = [_lstDishCollection objectAtIndex: indexPath.row]; 
     byoPizzaInfo = [_lstDishCollection objectAtIndex:indexPath.row]; 
     if (pizzaInfoCellData._bIsSelected) 
     {  
      cell.vSelectionView.hidden = NO; 
      pizzaInfoCellData._bIsSelected = NO; 
      [self._byodelegate deltaDeSelection:pizzaInfoCellData]; 
     } 
     else 
     { 
      cell.vSelectionView.hidden = YES; 
      pizzaInfoCellData._bIsSelected = YES; 
      // deltaSelection:(pizzaInfo *)selectedItem 
      [self._byodelegate deltaSelection:pizzaInfoCellData]; 
      if (self._IsNotifiable) {    
       [self showView];    
      } 
     } 
     [_vCVC reloadData]; 
} 

よりは内部でtableViewCell.

+0

コードのインデントが悪いです。コードを理解するのに今や多くの時間がかかるので、あなたを助けることは非常に困難です。 – Shubhank

答えて

2

あるごcellForItemAtIndexPathあなたはすでに非表示のための条件を追加し、あなたのようなあなたのdidSelectItemAtIndexPathを変更する必要があるので、選択したビューを表示していますこの

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    pizzaInfo *pizzaInfoCellData = [_lstDishCollection objectAtIndex: indexPath.row]; 
    if (pizzaInfoCellData._bIsSelected) 
    {  
      [self._byodelegate deltaDeSelection:pizzaInfoCellData]; 
    } 
    else 
    { 
      [self._byodelegate deltaSelection:pizzaInfoCellData]; 
    } 
    pizzaInfoCellData._bIsSelected = !pizzaInfoCellData._bIsSelected 
    [_vCVC reloadData]; 
} 

注:クラス名は常に大文字で始まるので、クラス名をpizzaInfoに変更するとバッターになります。PizzaInfo、良いコーディングガイドラインの提案。

+0

ありがとうございました。しかし、選択をスクロールしている間はまだまだです。 [self._byodelegate deltaDeSelection:pizzaInfoCellData]/[self._byodelegate deltaSelection:pizzaInfoCellData];これらのコード行は、オブジェクトを配列から削除/追加しているので、elseブロックを使用している理由です。再度確認してください。 –

+0

@Mac_Play編集した回答を確認してください。 –

関連する問題