dancingbush
dancingbush

Reputation: 2281

Wrapping a collection view in a view controller nil delegate error

I have a view controller wrapping a scrollview which then holds a collection view and a content view. When I run I get a null pointer exception assigning the collection view delegate in viewDidLoad:

collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.clearColor()

Not sure why, i have implemented protocols and made a connection to view controller as follows;

class LayoutController2 : UIViewController , UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate {

 @IBOutlet weak var collectionView: UICollectionView!

Any Input appreciated.

Upvotes: 2

Views: 526

Answers (1)

Karim Sallam
Karim Sallam

Reputation: 93

is the collectionView outlet connected in the storyboard? It's implicit unwrapped so if you access the delegate and the collectionView is not connected it will blow up

Upvotes: 2

Related Questions