我的 UITableView
标题中有一个 UICollectionView
。如果没有数据,我会删除 collectionView。
我在行“self.collectionView.reloadData()
”
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/