Я пытаюсь заполнить collectionView следующим кодом, однако он всегда пуст. Я не могу понять, в чем проблема. Вот переменные после self.collectionView.reloadData()
строки выполняется::Population UICollectionView не работает
import UIKit
class SingleChatFull: UIViewController,UICollectionViewDelegate, UICollectionViewDataSource, openUserChat {
var chat_m = [Message]()
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.backgroundColor = UIColor.whiteColor()
// Do any additional setup after loading the view.
}
func canOpenUserChat(messages: [Message]) {
chat_m = messages
dispatch_async(dispatch_get_main_queue()) {
self.collectionView.reloadData()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return chat_m.count
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("message_cell" , forIndexPath: indexPath) as! DisplayMessageCollectionViewCell
cell.messageTextView.text = chat_m[indexPath.row].text
cell.backgroundColor = UIColor.blueColor()
return cell
}