2015-08-24 37 views
0

我的代碼:UICollectionView - 爲什麼幀標籤不工作在第一和第二單元 - 迅速

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as? GuideGalleryCell 
    cell!.configureCell(listImages[indexPath.row]) 
    return cell! 
} 

代碼 - 功能configureCell:

func configureCell(_imageText:ImageText){ 
    imageText = _imageText 

    image = System.retrieveImage(imageText.nvImage, fromCity: System.instance().currentOrder.packageName) 
    imageView.image = image 
    //  if let text = imageText.nvText{ 
    lblTitle.text = imageText.nvText 
    var s:NSString=imageText.nvText 

    var frame = self.viewLblTitle.frame 
    frame.origin.y = self.bounds.size.height 
    self.viewLblTitle.frame = frame 

    var frmageImage = image.size 
    if(!(s.isEqualToString(""))) 
    { 

     UIView.animateWithDuration(0.7, animations: {() -> Void in 
      if self.image.size.height > self.image.size.width{ 
       var newY = (self.image.size.height - self.viewLblTitle.frame.size.height) 
       var frame = self.viewLblTitle.frame 
       frame.origin.y = newY 
       self.viewLblTitle.frame = frame 
      }else{ 
       var t = (self.bounds.size.height - 64 - self.image.size.height)/2 
       var newY = self.image.size.height - self.viewLblTitle.frame.size.height + t 
       println(newY) 
       var frame = self.viewLblTitle.frame 
       frame.origin.y = newY 
       self.viewLblTitle.frame = frame 
      } 
     }) 

    } 
} 

的viewLblTitle的框架不工作第一個和第二個細胞只跟隨它工作的細胞,爲什麼? 它可能是什麼? 當我回到第二個和第一個單元格時,它一直運行良好,

很奇怪,不是嗎? 感謝手錶!

回答

0

現在,它的工作原理! 我說:

dispatch_async(dispatch_get_main_queue()) 

調用函數之前configureCell

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell:GuideGalleryCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! GuideGalleryCell 
    dispatch_async(dispatch_get_main_queue()) { 
     cell.configureCell(self.listImages[indexPath.row]) 
    } 
    return cell 
} 

現在,它的作品好! :)

相關問題