2016-06-17 6 views
0

manchmal Fortschrittsbalken meine ColectionViewCell die nicht sichtbar ist,
i in jeder Zeile einige Elemente haben und unten bin versucht ProgressBar eines einzelnen Elements zu verstecken, aber mein Fortschrittsbalken bekam versteckt von allen Elementen einer Zeileeine Ansicht von einem einzigen Element in Reihe (collectionViewCell Item) verstecken

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 
    } 

eine Idee, wie das zu beheben ???

+0

, wenn Ihre Fortschrittleiste ausgeblendet? Welche Zelle hast du versteckt? –

+0

Ich dint dir Mann @IyyappanRavi, was du fragst? –

Antwort

2

Nur ein kurzer Überblick, so dass Sie Ihre Antwort erhalten

UICollectionView ist stark optimiert und somit nur auf dem Bildschirm sichtbare Zeilen im Speicher halten. Jetzt sind alle Zeilen Zellen im Pool zwischengespeichert und werden wiederverwendet und nicht neu generiert. Immer wenn der Benutzer die UICollectionView scrollt, fügt er die gerade versteckten Zeilen in Pool hinzu und verwendet sie erneut, damit die nächsten sichtbaren Zeilen angezeigt werden.

jetzt in deine Antwort Also, kommen,

Wenn Sie Ihre Collection bewegen, wird Kollektiondatenquelle Methode für jeden indexPath erneut aufgerufen, und es wieder verwendet, die verborgenen Zellen, also in anderer Zelle, wo Sie Ihre verstecken Fortschrittsbalken, wird wiederverwendet und es zeigt immer noch Fortschrittsbalken

versteckt
  • (UICollectionViewCell *) Collection: (UICollectionView *) Collection cellForItemAtIndexPath: (NSIndexPath *) indexPath

SOLUTION

IHR PROGRESS BAR VISIBILITY RESET für jede Zelle auf Abruf von 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

danke mann jetzt funktioniert es ganz gut, schätze dich –

+1

Froh, zu helfen! :) –

2

Angenommen, Sie haben feste Anzahl von Zellen in UICollectionView.

Tipp zur Lösung eines solchen Problems, when you have controls in UICollectionViewCell or UITableViewCell, give tag to your controls depending upon your indexPath.

Fall 1: Wenn Collectionschnitt ist, dann wird Ihre Tags wie [0] [0], [1] [0] ... In einem solchen Fall tun so etwas,

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

Fall 2: Wenn Sammlung Ansicht ist nicht Schnitt, so etwas tun,

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

hoffen, dass dies Ihr Problem lösen oder Ihnen Idee, entsprechend zu verwalten. Wenn Sie mehr als ein Steuerelement in Ihrer Zelle haben, dann geben Sie einfach Tags wie indexPath.item + 1 + 2 ...