DataService.dataService.fetchDataFromServer { (channel) in
self.channels.append(channel)
let indexPath = IndexPath(item: self.channels.count - 1, section: 0)
self.collectionView?.insertItems(at: [indexPath])
}
Abrufen von Daten vom Server Funktion:
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)
})
}
Nummer von Artikel Abschnitt:
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return 0
}
der vollständige Fehler:
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'
Ich arbeite mit einer Sammlungsansicht und habe keine Ahnung, warum dieser Fehler angezeigt wird.
Jede Hilfe wäre willkommen!
Zeigen Sie Ihre 'numberOfItemsInSection' Methode – Paulw11
einfach hinzugefügt werden. Sieh es dir an! –
Sie geben 0 zurück. Wahrscheinlich möchten Sie 'self.channels.count' zurückgeben. – Paulw11