简体   繁体   中英

PFQueryTableViewController - CellForRowAtIndexPath is not being called/is not working

I've been trying to implement a PFQueryTableViewController in order to show the data from my Parse server to the user. For whatever reason, my custom prototype cell is not being used at all. Rather, the table is just displaying (the x's represents numbers). I've checked to ensure that all of my outlets are hooked up properly and that the reuse identifier is corresponding to the one I set in the storyboard. Not sure what the issue could be. My code for the PFQueryTableViewController and the PFTableViewCell is below. I'd appreciate if anybody could help me out.

PFQueryTableViewController Class:

import UIKit
import ParseUI
import Parse

class HomePagePFQueryTable: PFQueryTableViewController {



override func queryForTable() -> PFQuery<PFObject>
{
    let query = PFQuery(className: "Posts")
    //query.cachePolicy = .cacheElseNetwork
    query.order(byDescending: "createdAt")
    return query
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell?
{
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath) as! HomePagePFQueryTableCell

    cell.titleLabel?.text = object?.object(forKey: "Title") as? String

    let imageFile = object?.object(forKey: "imageFile") as? PFFile
    print(cell.titleLabel.text)
    cell.mainImageView?.file = imageFile

    cell.mainImageView.loadInBackground()

    return cell
}




override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    print("Loaded")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

PFTableViewCell Class:

import UIKit
import Parse
import ParseUI

class HomePagePFQueryTableCell: PFTableViewCell {
@IBOutlet weak var mainImageView: PFImageView!

@IBOutlet weak var titleLabel: UILabel!
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
    // Drawing code
}
*/

}

Wow, just figured it out. All I had to do was place a _ in front of the first tableView in the cellForRowAtIndexPath function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM