내 코드 업데이트 후이 있습니다 :오류 : 섹션 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'
컬렉션보기로 작업 중이며이 오류가 표시되는 이유를 찾을 수 없습니다.
도움이 될 것입니다.
이 – Paulw11
단지를 추가하여'numberOfItemsInSection' 방법을 표시 :
코드는 심지어 코멘트
// #warning Incomplete implementation, return the number of items
당신은 아마 뭔가를 원하는에게 있습니다. 보세요! –
0을 돌려줍니다. 아마도'self.channels.count'를 돌려 주길 원할 것입니다. – Paulw11