无法从 PFQueryCollectionViewController 中的 Parse 加载数据 Swift iOS

Cannot load data from Parse in PFQueryCollectionViewController Swift iOS

我在将数据从 Parse 加载到我的 PFQueryCollectionViewController 时遇到问题。这是我的 WaterfallFeedCollectionViewController Class:

 import UIKit
 import Parse

class WaterfallFeedCollectionViewController: PFQueryCollectionViewController, CollectionViewWaterfallLayoutDelegate {

@IBOutlet var theCollectionView: UICollectionView!
//Random high Cells
lazy var cellSizes: [CGSize] = {
    var _cellSizes = [CGSize]()

    for _ in 0...20 {
        let random = Int(arc4random_uniform((UInt32(100))))

        _cellSizes.append(CGSize(width: 140, height: 150 + random))
    }

    return _cellSizes
    }()

init!(style: CollectionViewWaterfallLayout, className: String!) {
    super.init(collectionViewLayout: style, className: className)
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    // Configure the PFQueryCollectionView
    self.parseClassName = "foodEntry"
    self.pullToRefreshEnabled = true
    self.paginationEnabled = true
    self.objectsPerPage = 15
}


override func queryForCollection() -> PFQuery {
    var query = PFQuery(className: "foodEntry")
    query.orderByAscending("createdAt")

    return query
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let layout = CollectionViewWaterfallLayout()
    layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    layout.headerInset = UIEdgeInsetsMake(0, 0, 0, 0)
    layout.headerHeight = 0
    layout.footerHeight = 0
    layout.minimumColumnSpacing = 10
    layout.minimumInteritemSpacing = 10

    theCollectionView.collectionViewLayout = layout
    theCollectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: CollectionViewWaterfallElementKindSectionHeader, withReuseIdentifier: "Header")
    theCollectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: CollectionViewWaterfallElementKindSectionFooter, withReuseIdentifier: "Footer")
}

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
}

//Zelle
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFCollectionViewCell {

    var cell = theCollectionView.dequeueReusableCellWithReuseIdentifier("myWaterfallCell", forIndexPath: indexPath) as myWaterfallCollectionViewCell
    cell.FoodNameLabel.text = object["FoodName"] as? String

    var text = object["FoodName"] as? String
    println("\(text) funktioniert")

    return cell
}

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {

    var reusableView: UICollectionReusableView? = nil

    if kind == CollectionViewWaterfallElementKindSectionHeader {
        reusableView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Header", forIndexPath: indexPath) as? UICollectionReusableView

        if let view = reusableView {
            view.backgroundColor = UIColor.redColor()
        }
    }
    else if kind == CollectionViewWaterfallElementKindSectionFooter {
        reusableView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Footer", forIndexPath: indexPath) as? UICollectionReusableView
        if let view = reusableView {
            view.backgroundColor = UIColor.blueColor()
        }
    }

    return reusableView!
}

// MARK: WaterfallLayoutDelegate

override func collectionView(theCollectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    return cellSizes[indexPath.item]
}

}

它总是 returns 零。 Parse 的文档对于 CollectionView 来说真的很糟糕。我找到了一个示例项目,并试图用它来解决它以及它们在 PFQueryTableView 中加载数据的方式。拉动刷新有效,所以我猜它是正确的方式。

上面的代码确实有效。我现在通过 pods 添加的 ParseUI 框架存在问题。