vbv111
vbv111

Reputation: 35

UICollectionView is not appearing

When i build my project (simulator/device) UICollectionView is not appearing.

I set (i think so) all delegates,functions etc. And i still dont have that view.

class WeatherViewController: UIViewController, CLLocationManagerDelegate,UICollectionViewDelegate,UICollectionViewDataSource{


    @IBOutlet weak var collectionView: UICollectionView!


    var forecast: Forecast!
    var forecasts = [Forecast]()


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        collectionView.delegate = self
        collectionView.dataSource = self
    }

    func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int{
        return 1
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return forecasts.count
    }


    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ForecastCell", for: indexPath) as? ForecastCollectionViewCell {
            let forecast = forecasts[indexPath.row]
            cell.updateForecastCell(forecast: forecast)
            return cell
        } else {
            return ForecastCollectionViewCell()
        }
    }

}

Upvotes: 0

Views: 55

Answers (1)

kuzdu
kuzdu

Reputation: 7524

I downloaded the project and removed the dataSource and the delegate from storyboard because you set them already inside code.

You work with Stack Views. When I move your collectionView out of the Stack Views your code works as expected.

Unfortunately I don't know why you can't put a collectionView inside Stack View. Maybe you will find a solution then please post.

(My personal opinion: I really don't like Stack Views. It seems that they make you life easier but I can't apply with that.) enter image description here

Upvotes: 1

Related Questions