gpt4 book ai didi

ios - UICollectionView reloadData - EXC_BREAKPOINT

转载 作者:行者123 更新时间:2023-11-28 08:21:53 25 4
gpt4 key购买 nike

我的 UITableView 标题中有一个 UICollectionView。如果没有数据,我会删除 collectionView。我在行“self.collectionView.reloadData()

中遇到 EXC_BREAKPOINT 崩溃
var reccomend: [JSON]? = []

func loadReccomend(){
YazarAPI.sharedInstance.loadReccomendedArticles({ reccomend in
if let data = reccomend["articles"].arrayValue as [JSON]?{
self.reccomend = data
if (self.reccomend?.count)! < 1 {
self.tableView.tableHeaderView = nil
}else{
self.collectionView.reloadData()
}
}
})
}

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.reccomend?.count ?? 0
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ReccomendCell", forIndexPath: indexPath) as! ReccomendedCollectionViewCell
cell.article = self.reccomend?[indexPath.row]
return cell
}

print(data) 的结果:

[{
"title" : "title0",
"author_email" : null,
"author_id" : 1884,
"read_count" : 0,
"is_favorite" : false,

}, {
"title" : "title1",
"author_email" : null,
"author_id" : 1884,
"read_count" : 0,
"is_favorite" : false,

}]

最佳答案

尝试在你的 else 部分使用 guard:

 guard self.reccomend?.count > 0 else{
return
}
self.collectionView.reloadData()

关于ios - UICollectionView reloadData - EXC_BREAKPOINT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41054400/

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