gpt4 book ai didi

ios - UICollectionView 没有出现

转载 作者:行者123 更新时间:2023-11-28 15:15:37 25 4
gpt4 key购买 nike

当我构建我的项目(模拟器/设备)时,UICollectionView 没有出现。

我设置了(我认为是)所有委托(delegate)、函数等。但我仍然没有那个 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()
}
}

}

最佳答案

我下载了项目并从 storyboard 中删除了 dataSourcedelegate,因为您已经在代码中设置了它们。

您使用 Stack Views。当我将您的 collectionView 移出 Stack Views 时,您的代码会按预期工作。

不幸的是,我不知道为什么不能在 Stack View 中放置一个 collectionView。也许您会找到解决方案,然后请发布。

(我个人的意见:我真的不喜欢 Stack Views。看起来它们让你的生活更轻松,但我不能应用它。) enter image description here

关于ios - UICollectionView 没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46912026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com