我从解析中的数据填充数组。该数组正在填充,但是当我将它添加到集合视图并刷新视图时,什么也没有显示。我该如何解决?是否有某个地方需要刷新收藏视图?填充该数组:为什么收藏视图不能重新加载?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
getFriendName()
getFriendPic()
}
func getFriendPic(){
let imagequery = PFQuery(className: "_User")
imagequery.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in
// for object in objects!{
var user = PFUser.currentUser()
let relation = user!.relationForKey("Friendship")
relation.query()!.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!)
self.arrayOfFriends.append(image!)
print(self.arrayOfFriends)
}
self.collectionView.reloadData()
})
}
}
}
}
func getFriendName(){
var query = PFQuery(className: "_User")
query.findObjectsInBackgroundWithBlock({
(objects: [AnyObject]?, error: NSError?) -> Void in
var user = PFUser.currentUser()
let relations = user!.relationForKey("Friendship")
relations.query()!.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]?, error: NSError?) -> Void in
var objectIDs = objects as! [PFObject]
for i in 0...(objectIDs.count){
self.arrayOfFriendsNames.append(objectIDs[i].valueForKey("username") as! String)
print(self.arrayOfFriendsNames)
}
self.collectionView.reloadData()
}
})
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: friendcellView = collectionView.dequeueReusableCellWithReuseIdentifier("friendcell", forIndexPath: indexPath) as! friendcellView
cell.friendname.text = arrayOfFriendsNames[indexPath.item]
cell.friendpic.image = arrayOfFriends[indexPath.item]
cell.friendpic.layer.cornerRadius = cell.friendpic.frame.size.width/2;
cell.friendpic.clipsToBounds = true
return cell
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrayOfFriendsNames.count
}
,你回到小区 – anhtu