Reputation: 2281
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
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