2016-07-04 3 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() 
      }) 

``` 을 시도하고이에 스크롤입니다 하단 기능

```

```

관련 문제