我的代码:
DataService.dataService.fetchDataFromServer { (channel) in
self.channels.append(channel)
let indexPath = IndexPath(item: self.channels.count - 1, section: 0)
self.collectionView?.insertItems(at: [indexPath])
}
从服务器函数获取数据:
func fetchDataFromServer(callBack: @escaping (Channel) -> ()) {
DataService.dataService.CHANNEL_REF.observe(.childAdded, with: { (snapshot) in
let channel = Channel(key: snapshot.key, snapshot: snapshot.value as! Dictionary<String, AnyObject>)
callBack(channel)
})
}
项目数量部分:
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return 0
}
完整错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert item 0 into section 0, but there are only 0 items in section 0 after the update'
我正在使用集合视图,但不知道为什么会出现此错误。
任何帮助,将不胜感激!