我有一个集合视图,我想显示每小时的天气。我似乎有一个加载单元格的问题,并且由于某种原因向前滚动然后返回完全加载单元格。在我滚动集合视图之前,所有约束都不起作用,并且一个标签没有显示它的信息。
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()
}
答案 0 :(得分:3)
好像你异步填充你的单元格,如果是这样,那么最后添加一个mycollectionview.reloadData()。
答案 1 :(得分:2)
我通过在cell.layoutIfNeeded()
之前添加return cell
来解决问题。所有内容都按预期加载而不进行任何滚动!