【问题标题】:Only 1 Section Showing PFQueryCollectionViewController只有 1 个部分显示 PFQueryCollectionViewController
【发布时间】:2023-03-23 22:01:02
【问题描述】:

我正在从 Parse 中提取图像并将它们加载到 PFQueryCollectionViewController 中。查询运行并拉取图像。然而,它只返回一行图像而不是多行图像。有很多图像。我已经被这个卡住了一段时间,它让我发疯。

如果我设置了基本的override func numberOfSectionsInCollectionViewoverride 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


    【解决方案1】:

    问题在于试图覆盖在 Storyboard 上实现的布局设置。大多数常量属性不是在PFQueryCollectionViewController 中以编程方式设置布局和单元格属性的规范,而是在属性检查器中设置。

    当然,这遵循这样的规则,即 10 次中有 9 次它比你想要的更简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多