grabury grabury - 1 year ago 172
Swift Question

CollectionView datasource and delegate methods not being called

The UICollectionView's datasource and delegate methods are not being called. I have

class MessagesViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
self.collectionView.dataSource = self
self.collectionView.delegate = self

And the function

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell

is not being called.

Answer Source

I can't write a comment because of low reputation, but my guess would be that you set the dataSource and delegate in the viewDidLoad() method. Perhaps hook the dataSource and delegate up in the storyboard by control-dragging from your CollectionView to the ViewController containing it. You could also try reloading the collectionView data with collectionView.reloadData() after you set the dataSource and delegate in viewDidLoad().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download