Моего кода:ОШИБКИ: Попытка вставить элемент 0 в раздел 0, но есть только 0 пунктов в разделе 0 после обновления
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'
Я работаю с коллекцией и не знаю, почему эта ошибка появляется.
Любая помощь будет оценена!
Покажите свой 'numberOfItemsInSection' метод – Paulw11
только что добавили его. Посмотрите! –
Вы возвращаетесь 0. Вы, вероятно, захотите вернуть 'self.channels.count' – Paulw11