同步从解析和Swift拍摄的照片

时间:2016-06-14 08:53:23

标签: ios swift parsing uicollectionview dispatch-async

嗨我有一个集合视图,我填写了我从解析中拍摄的照片。 我用2部分代码完成:

var magazia = [String]()
    var id = [PFFile]()

首先在viewDidLoad里面:

let query = PFQuery(className:"magazia")
        query.limit = 1000
        query.whereKey("typeTag", equalTo: " Cafe - Bar")
        query.findObjectsInBackgroundWithBlock {
            (objects: [PFObject]?, error: NSError?) -> Void in

            if error == nil {
                if let objects = objects {
                    for object in objects {

                        let loadmagazia = object.objectForKey("name") as! String
                        self.magazia.append(loadmagazia)
                        let idmag = object.objectForKey("logo") as! PFFile
                        self.id.append(idmag)



                    }
                }
            } else {

                print("Error: \(error!) \(error!.userInfo)")
            }
            self.indicator.stopAnimating()
            self.indicator.hidden = true
            self.count.text = "Βρέθηκαν \(self.magazia.count) μαγαζιά"

            self.collectionView.reloadData()
        }

第二个内部集合的视图功能:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath: indexPath) as! ThirdTabCell

        id[indexPath.row].getDataInBackgroundWithBlock{
            (imageData: NSData?, error: NSError?) -> Void in

            if imageData != nil{
                let image = UIImage(data: imageData!)
                cell.featuredImageView.image = image
                cell.drinkTitle.text = self.magazia[indexPath.row]
            } else {
                print(error)
            }

        }

        return cell
    }

一切都很好但是当我滚动查看我的收藏视图的单元格时,我会看到之前的照片片刻,然后重新加载!

请帮助:D

0 个答案:

没有答案