【发布时间】:2018-05-05 18:40:17
【问题描述】:
var posts = [Post]()
....
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! FeedCollectionViewCell
cell.postTextView.text = posts[indexPath.item].caption
cell.postImageView.image = UIImage(named: "photoplaceholder.jpg")
let urlString = posts[indexPath.item].photoUrl
let url = URL(string: urlString)
let task = URLSession.shared.dataTask(with: url!){ data, reponse, error in
if error != nil {
print(error!)
} else{
DispatchQueue.main.async(execute: {
cell.postImageView.image = UIImage(data: data!)
})
}
}
task.resume()
return cell
}
}
我想显示最新的帖子而不是最旧的帖子。 而对于 tableview,posts[indexPath.row].caption 给了我最新的帖子, 对于 UICollectionView 它没有,它给了我最古老的帖子。我需要有关如何在其他帖子之前先显示最新帖子的帮助。
【问题讨论】:
标签: ios swift firebase uicollectionview