무엇 아마 무슨 일이 일어나고은 경쟁 조건이다 : 나는 또한이 시도
guard let uid = FIRAuth.auth()?.currentUser?.uid, let toId = user?.id else {
return
}
let userMessagesRef = FIRDatabase.database().reference().child("user-messages").child(uid).child(toId)
userMessagesRef.observe(.childAdded, with: { (snapshot) in
guard let messageId = snapshot.key as? String else {
return
}
let messagesRef = FIRDatabase.database().reference().child("messages").child(messageId)
messagesRef.observeSingleEvent(of: .value, with: { (snapshot) in
guard let dictionary = snapshot.value as? [String: AnyObject] else {
return
}
self.messages.append(Message(dictionary: dictionary))
DispatchQueue.main.async(execute: {
self.collectionView?.reloadData()
//scroll to the last index
if self.messages.count > 0 {
if let indexPath = IndexPath(item: self.messages.count - 1, section: 0) as? IndexPath? {
self.collectionView?.scrollToItem(at: indexPath!, at: .bottom, animated: false)
}
}
})
}, withCancel: nil)
}, withCancel: nil)
}
:
이
내가 collectionView의 하단으로 스크롤을 사용하고있는 코드입니다
self.collectionView?.reloadData()
을 수행하고 바로 그 다음으로
collectionView
을 스크롤하려고합니다. Item이 준비되지 않았거나 예외가 발생하는 경우도 있습니다.
또한 중첩 된 async
전화가있는 것으로 보입니다. 해야 할 일 :
dispatch
중에서 self.collectionView?.reloadData()
을 이동하십시오.
- 스크롤하려는
indexPath
의 항목이 실제로는 scrollToItem
을 수행하기 전에 존재하는지 확인하십시오. 마지막 Item
이 UICollectionViewDataSource
내에서 생성 한 다음 스크롤 동작을 실행 할 때마다
또 다른 방법 그 대신 내부 Firebase
전화를 스크롤이 될 수있다, 당신은 확인.
가능한 중복 예외] (https://stackoverflow.com/questions/46700716/scroll-to-bottom-of-collectionview-without-animation-and-without-invalid-path-ex) – jvrmed
죄송합니다. 그 질문에 대한 답변을 얻지 못했습니다. 다시 게시하십시오! 그 질문을 삭제하고 있습니다. –
크래시 메시지 오류 (인쇄물, 로그 등)에 대한 자세한 정보를 공유하면 어딘가에서 쉽게 안내 할 수 있습니다. – jvrmed