2016-06-17 8 views
0

時々ColectionViewCellの進行状況バーが表示されない
すべての行にいくつかの項目があり、その下にあるProgressBarを非表示にしようとしていますが、行のすべての項目から非表示Row(collectionViewCell Item)内の単一の項目からビューを非表示にする

func collectionView(collectionView: UICollectionView, 
         cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", 
                     forIndexPath: indexPath) as! CollectionViewCell 

     let url = NSURL(string: "\(attachedImgUrlDict[collectionView.tag]![indexPath.item])")// its a Url 
      cell.imgViewOfCell.sd_setImageWithURL(url, placeholderImage: nil, options: SDWebImageOptions.CacheMemoryOnly, progress: { 
       (receivedSize, expectedSize) -> Void in 
       // Update progress here 

       cell.loaderView.progress = CGFloat(receivedSize)/CGFloat(expectedSize) 

      }) { 
       (image, error, _, _) -> Void in 
       // Reveal image here 

       cell.imgViewOfCell.image = self.ResizeImage(image , targetSize: CGSizeMake(cell.imgViewOfCell.frame.width , cell.imgViewOfCell.frame.height)) 

       cell.loaderView.hidden = true // am hiding the progress bar here when the loads complete (of a single item) but seems like its hiding the progressView of all items in the row 

      } 
     return cell 
    } 

どのようにこれを修正するか?あなたの答えを得るので

+0

のようなタグを入力してください。あなたは隠したセルですか? –

+0

私はあなたに何を求めているのですか?IyyappanRaviあなたは何を求めていますか? –

答えて

2

だけで簡単な概要は、

UICollectionViewは、高度に最適化されたため、メモリ内にのみオンスクリーン表示される行を維持しています。現在、すべての行のセルはプールにキャッシュされ、再利用され、再生成されません。ユーザーはUICollectionViewをスクロールするたびに、Pool内に隠れた行を追加し、次に見える行のためにそれらを再利用します。

だから、今、あなたの答えに来

あなたのCollectionViewをスクロールし、collectionViewデータソースの方法は、すべてのindexPathのために再び呼び出され、そしてそれはあなたが非表示他の細胞にこのように、隠された細胞を再利用し、あなたのプログレスバーは、再利用されますと、それはまだ、プログレスバーに隠さ

  • (UICollectionViewCell *)collectionView示しています(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

SOLUTION

あなたはUICollectionView中の細胞数を固定していると仮定すると、cellForItemAtIndexPath

func collectionView(collectionView: UICollectionView, 
         cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", 
                     forIndexPath: indexPath) as! CollectionViewCell 

     cell.loaderView.hidden = false //RESET ITS VISIBILITY 


     let url = NSURL(string: "\(attachedImgUrlDict[collectionView.tag]![indexPath.item])")// its a Url 
      cell.imgViewOfCell.sd_setImageWithURL(url, placeholderImage: nil, options: SDWebImageOptions.CacheMemoryOnly, progress: { 

       //SAME CODE 

      } 
     return cell 
    } 
+0

ありがとう、今、その仕事はきれいで、ありがとうございます –

+1

助けてくれてありがとうございます! :) –

2

の呼び出しでセルごとにあなたのプログレスバーの可視性をリセットします。 、when you have controls in UICollectionViewCell or UITableViewCell, give tag to your controls depending upon your indexPathを、このような問題を解決するための

ヒント。

ケース1:CollectionViewが断面であれば、あなたのタグが[0] [0]、[1] [0] ...このような場合には、このような何かを行う

collectionViewCell.progressBar.tag = [[NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.item] intValue]; // If it is sectional collection view 

ケースのようになります2:コレクションビューが非断面である場合には、このような何かを、これはあなたの問題を解決したり、それに応じて管理するために、あなたのアイデアを与えるだろう

collectionViewCell.progressBar.tag = [[NSString stringWithFormat:@"%ld",(long)indexPath.item] intValue]; // If it is non-sectional collection view 

ホープ。 セルに複数のコントロールがある場合は、indexPath.item + 1 + 2 ...

関連する問題