UICollectionView 在滚动之前未完全加载

fel*_*mer 6 cocoa-touch ios uicollectionview uicollectionviewcell swift

我有一个集合视图,我想在其中显示每小时的天气。我似乎在加载单元格时遇到问题,并且由于某种原因向前滚动然后向后滚动完全加载单元格。在我滚动集合视图之前,所有约束都不起作用,并且一个标签不显示其信息。

\n\n

滚动之前\n滚动之前

\n\n

滚动后(这就是我想要的单元格的样子)\n滚动后(这就是我想要的单元格的样子)

\n\n
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {\n    // #warning Incomplete implementation, return the number of sections\n    return 1\n}\n\n\nfunc collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {\n    // #warning Incomplete implementation, return the number of items\n    return newhourlyWeather.count\n}\n\nfunc collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {\n    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! hourlyWeatherCell\n\n    // Configure the cell\n\n    let hWeather = newhourlyWeather[indexPath.row]\n\n    if let HourlyTemp = hWeather.temperatureh {\n        cell.temperatureHLabel.text = "\\(HourlyTemp)\xc2\xba"\n    }\n\n    if let HourlyTime = hWeather.convertedTimeH {\n        cell.timeHLabel.text = "\\(HourlyTime)"\n    }\n\n    if let HourlyRain = hWeather.precipProbabilityh {\n        cell.rainChanceHLabel.text = "\\(HourlyRain)%"\n    }\n\n     cell.iconhView.image = hWeather.iconh\n\n    return cell\n\n    self.collectionView.reloadData()\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Dam*_*rot 4

似乎您异步填充单元格,如果是这样,则在末尾添加 mycollectionview.reloadData() 。