Xcode 6 tells me that UIViewController has no member named reloadData ()

I have a view controller that is UICollectionViewController

, UICollectionViewDataSource

and UICollectionViewDelegate

.

After updating Xcode recently, I get the following error:

'(UICollectionView, numberOfItemsInSection: Int) -> Int' has no member named 'reloadData'

in the following code ( -didCompleteForecast:

- callback method):

func didCompleteForecast() {
    //stuff
    println("got the data back")

    dispatch_async(dispatch_get_main_queue()) {
        self.collectionView.reloadData()
    }

      

According to Apple's own documentation, -reloadData:

should be available.

What am I missing?

thank

+3


source to share


2 answers


because self.colectionView is an optional type (UICollectionView?), so you need to expand it:



self.collectionView!.reloadData()

      

+6


source


You might get an error like this if you're dealing with a standard UIViewController

to which you've added a collection view but neglected to define an outlet / property function called collectionView

.

In this situation, the reference collectionView

in didCompleteForecast

will match the first method UICollectionViewDelegate

that you implemented in your class (presumably a method numberOfItemsInSection

based on your error message).




As Aditya correctly pointed out, you will also get this error with help UICollectionViewController

if you don't expand the optional collectionView

.

0


source







All Articles