gpt4 book ai didi

ios - `numberOfItemsInSection` 仅在添加数组中的第一项后调用,将项目限制为只有一个

转载 作者:可可西里 更新时间:2023-11-01 00:41:38 27 4
gpt4 key购买 nike

目前我有一个 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 中。它触发 collectionview 的 numberOfItemsInSection,这将部分中的项目总数限制为 1。tableview 的 knownForArray 可以有 50 多个项目,在它完成检索所有 JSON 数据之后。

最佳答案

每当网络调用完成时,您都需要调用 collectionView.reloadData()

关于ios - `numberOfItemsInSection` 仅在添加数组中的第一项后调用,将项目限制为只有一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42936374/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com