我无法使用用户名填充评论。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! HomeTableViewCell
cell.postsText.text = postLists[indexPath.row].postText
i = indexPath.row
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (postLists[i].imageUrlList?.count)!
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! PhotosCollectionCell
let url = postLists[i].imageUrlList![indexPath.row]
let imgUrl = URL(string: url)
URLSession.shared.dataTask(with: imgUrl!, completionHandler: { (data, response, error) in
if error != nil {
// if download hits an error, so lets return out
print(error)
return
}
// if there is no error happens...
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { // in half a second...
cell.postPhoto.image = UIImage(data: data!)
}
}).resume()
return cell
}