0
したがって、現在のコードでは、messageCountから返された数値に関係なく、リストはまったくスクロールされません。これはviewDidLoad()にあり、データはFirebaseによって読み込まれます。それが原因ですか?UICollectionViewの一番下にスクロールする方法は?
現在のコード:
self.messages.removeAll()
collectionView?.reloadData()
refHandle = self.ref.child("messages").observeEventType(.ChildAdded, withBlock: { (snapshot) -> Void in
self.messages.append(snapshot)
self.collectionView?.insertItemsAtIndexPaths([NSIndexPath(forItem: self.messages.count - 1, inSection: 0)])
})
refHandle = ref.child("messages").observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) in
let messageCount = Int(snapshot.childrenCount)
print(messageCount) //temp
self.collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: messageCount - 1, inSection: 0), atScrollPosition: .Bottom, animated: true)
})
メインスレッド上で、それを呼び出して試してみてください – Chris