【发布时间】:2023-03-23 22:01:02
【问题描述】:
我正在从 Parse 中提取图像并将它们加载到 PFQueryCollectionViewController 中。查询运行并拉取图像。然而,它只返回一行图像而不是多行图像。有很多图像。我已经被这个卡住了一段时间,它让我发疯。
如果我设置了基本的override func numberOfSectionsInCollectionView 和override func numberOfItemsInCollectionView 方法,它会在加载显示[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array 的视图时返回错误
再次,确实出现了一行图像,但它没有继续到第二行。
class MasterCollection: PFQueryCollectionViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var cView: UICollectionView?
override func viewDidLoad() {
super.viewDidLoad()
self.objectsPerPage = 77
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)
layout.itemSize = CGSize(width: 100, height: 100)
cView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
cView!.dataSource = self
cView!.delegate = self
self.cView!.registerClass(MasterCollectionCell.self, forCellWithReuseIdentifier: reuseIdentifier)
cView?.backgroundColor = UIColor.greenColor()
self.view.addSubview(cView!)!
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
/*override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 100
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}*/
override func queryForCollection() -> PFQuery {
println("query ran")
var query: PFQuery = PFQuery(className: questionClass)
if (objects.count == 0) {
query.cachePolicy = PFCachePolicy.CacheThenNetwork
}
query.orderByAscending(objectId)
println(query)
return query
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFCollectionViewCell? {
let cell: MasterCollectionCell = self.collectionView!.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! MasterCollectionCell
cell.parseObject = object
if let pfObject = object {
let image = pfObject[questionImage] as? PFFile
cell.collectionCellImageView?.file = image
cell.collectionCellImageView?.loadInBackground()
}
return cell
}
这与我的问题类似,但我没有使用 TableView:Swift index 0 beyond bounds for empty array in tableview
【问题讨论】:
标签: ios swift parse-platform uicollectionview