目前我有一个UICollectionvView,可以从相应的UITableView单元获取信息,如下所示:
//TableView
var knownForArray: [UIImage] = []
var knownForExtendedArray: [CastExtendedData] = []
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = peopleImagesTableView.dequeueReusableCell(withIdentifier: knownForCellIdentifier) as! KnownForCell
print("Known for array count at cell:\(self.knownForArray.count)")
cell.imageDelegete = self
cell.knownForExtendedArray = self.knownForExtendedArray
cell.knownForArray = self.knownForArray
self.peopleImagesTableView.rowHeight = 150
return cell
}
//CollectionView
var knownForArray: [UIImage] = []
var knownForExtendedArray: [CastExtendedData] = []
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("Known for array count collectionview numberOfRowsInSection:\(self.knownForArray.count)")
return knownForArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = knownForCollectionView.dequeueReusableCell(withReuseIdentifier: knownForReuseIdentifier, for: indexPath) as! KnownForCollectionViewCell
if let knownPoster = knownForExtendedArray[indexPath.row].poster{
DispatchQueue.main.async {
print("collectionview knownForarray: \(self.knownForArray.count)")
cell.knownForImages.sd_setImage(with: URL(string: "\(baseImageURL)\(knownPoster)"))
}
}
return cell
}
通过添加print
语句,我可以在第一项添加到tableview的knownForArray
后立即告诉我。它触发了集合视图numberOfItemsInSection
,它将部分中的项目总数限制为1.在查看完所有内容后,表格视图knownForArray
可以有50多个项目JSON数据。
答案 0 :(得分:4)
只要您的网络通话结束,您就需要拨打collectionView.reloadData()
。