2016-07-04 10 views
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) 
    }) 
+0

メインスレッド上で、それを呼び出して試してみてください – Chris

答えて

0

閉鎖を観察

内でこの

`` `

DispatchQueue.main.async(execute: { 
       self.collectionView?.reloadData() 
       self.scrollToBottom() 
      }) 

` `` を試してみて、これはへスクロールです下の機能

`` `

` ``

関連する問題