【发布时间】:2017-02-21 19:41:15
【问题描述】:
我有一个集合视图,我想在其中显示每小时天气。我似乎在加载单元格时遇到问题,并且由于某种原因向前滚动然后向后滚动完全加载单元格。在我滚动集合视图之前,所有约束都不起作用,并且一个标签没有显示它的信息。
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return newhourlyWeather.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! hourlyWeatherCell
// Configure the cell
let hWeather = newhourlyWeather[indexPath.row]
if let HourlyTemp = hWeather.temperatureh {
cell.temperatureHLabel.text = "\(HourlyTemp)º"
}
if let HourlyTime = hWeather.convertedTimeH {
cell.timeHLabel.text = "\(HourlyTime)"
}
if let HourlyRain = hWeather.precipProbabilityh {
cell.rainChanceHLabel.text = "\(HourlyRain)%"
}
cell.iconhView.image = hWeather.iconh
return cell
self.collectionView.reloadData()
}
【问题讨论】:
-
知道什么问题我可能需要一些代码
-
没有代码和约束的进一步信息,这个问题无法回答。
-
更新问题@vikingosegundo
-
重新加载集合视图将填充单元格对我来说似乎不是一个好主意。
-
但是嘿:你是在返回后执行的,所以它永远不会被执行。
标签: ios swift cocoa-touch uicollectionview uicollectionviewcell