【发布时间】:2016-06-22 07:53:24
【问题描述】:
当我通过简单查询从 Parse-Server 加载图像时,我遇到了这个奇怪的问题。
我有一个叫做“食谱”的课程,我有这些专栏。
-
名称(字符串)
-
图像(文件)
等等
这是我从该类加载食谱的代码。
override func viewDidLoad() {
super.viewDidLoad()
queryRecipes("")
}
func queryRecipes(searchText:String) {
self.recipesArray.removeAllObjects()
let query = PFQuery(className: "Recipes")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (objects, error)-> Void in
if error == nil {
self.recipesArray = NSMutableArray(array: objects!)
// Reload CollView
self.recipesCollView.reloadData()
self.view.hideHUD()
// Hide/show the nothing found Label
if self.recipesArray.count == 0 { self.nothingFoundLabel.hidden = false
} else { self.nothingFoundLabel.hidden = true }
} else {
print(error)
} }
}
然后是集合视图代码
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return recipesArray.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("RecipesCell", forIndexPath: indexPath) as! RecipesCell
var recipesClass = PFObject(className: "Recipes")
recipesClass = recipesArray[indexPath.row] as! PFObject
cell.titleLabel.text = "\(recipesClass["name"]!)"
let imageFile = recipesClass["image"] as? PFFile
cell.coverImage.file = imageFile
cell.coverImage.loadInBackground(nil)
cell.layer.shouldRasterize = true
cell.layer.rasterizationScale = UIScreen.mainScreen().scale
return cell
}
在单元格文件中我有以下内容
import UIKit
import ParseUI
class RecipesCell: UICollectionViewCell {
/* Views */
@IBOutlet weak var coverImage: PFImageView!
@IBOutlet weak var titleLabel: UILabel!
}
我已经从图像视图中的 main.storyboard 设置了这个类。
所以问题是我有 10 张图片。 当我转到某个视图时,它会显示我可以在手机中看到的前 4 个视图,它会很好地加载它们。但是当我向下滚动以在接下来的 6 个单元格中查看更多内容时,它会显示例如
第 5 个单元格 -> 第 1 个单元格的图像,然后是第 5 个单元格的图像。 第 6 个单元格 -> 其他单元格之一的随机图像,然后继续。
但是当我刷新时我没有看到任何这种反应。
有人知道为什么会这样吗? 我认为我的代码是合法的,但我遗漏了一些东西。
感谢您的宝贵时间。
PS,tableview 也会发生这种情况。
PS2。我也试过这个。在情节提要中,我为 uiimage 设置了一个静态图像,但它仍然使这个东西加载不同的图像,然后加载正确的图像。
【问题讨论】:
标签: ios swift parse-platform swift2 uicollectionview