2015-10-26 70 views
0

我试图追加从解析数据库中检索到的图像,但没有任何内容被添加到UIImage数组中。如何追加检索到的图像?为什么图像没有被添加到数组中?

var arrayOfFriends: [UIImage] = [] 

func getFriendPic(){ 

    var imagequery = PFQuery(className: "_User") 
    imagequery.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in 
     for object in objects!{ 
      let userPic = object["ProPic"] as! PFFile 
      userPic.getDataInBackgroundWithBlock({ (imageData: NSData?, error: NSError?) -> Void in 
       if(error == nil){ 
        let image = UIImage(data: imageData!) 
        //breakpoint placed on line below, but app crashes with array out of bounds. 
        self.arrayOfFriends.append(image!) 
        print(self.arrayOfFriends) 
       } 
       dispatch_async(dispatch_get_main_queue()) { 
        self.collectionView.reloadData() 
       } 
      }) 

     } 
    } 
} 
+0

你是否已经开始使用调试器来查看代码中发生了什么? – Paulw11

+0

是的,该数组有0值 – xxtmanxx

+0

是的,但你的'imageQuery'返回任何对象? 'getDataInBackgroundWithBlock'是否返回任何数据? – Paulw11

回答

相关问题