Ios UICollectionView未出现

Ios UICollectionView未出现,ios,swift,Ios,Swift,构建项目模拟器/设备时,UICollectionView未出现 我设置了所有的代理、函数等,但我仍然没有这样的观点 class WeatherViewController: UIViewController, CLLocationManagerDelegate,UICollectionViewDelegate,UICollectionViewDataSource{ @IBOutlet weak var collectionView: UICollectionView! v

构建项目模拟器/设备时,UICollectionView未出现

我设置了所有的代理、函数等,但我仍然没有这样的观点

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()
        }
    }

}

我下载了项目,并从故事板中删除了数据源和委托,因为您已经在代码中设置了它们

您可以使用堆栈视图。当我将collectionView移出堆栈视图时,您的代码将按预期工作

不幸的是,我不知道为什么不能在堆栈视图中放置collectionView。也许你会找到一个解决方案,然后请张贴

我个人的看法:我真的不喜欢堆栈视图。看起来他们让你的生活更轻松,但我不能这样申请。

检查Forecast数组的计数。如果正确,我将从JSON下载日期。我查过了。一切正常添加一对打印语句以确认.count并确认cellForItemAt正在按预期调用。