0

I am creating an app that loads data into a UITableView from Parse. I used some code that seems to work for loading the retrieved data into the cells in the table, but it is buggy and I did some research and found the PFQueryTableViewController. This seems like the solution to my problem, but all the documentation is in Objective-C (which I do not have any experience coding in), and there are no tutorials from what I could find on how to use this class in Swift. There are a few snippets that talk about how to initialize it, but nothing that really goes through how to set it up in Swift. I tried to go through the Obj-C documentation and set it up myself in Swift but I can't seem to get it right and would really appreciate some help. Does anyone have a suggested resource or has anyone set one up and could step through how to do this in Swift?

EDIT: I have found some resources and tried to get it set up, the table view loads but nothing is loaded into the cells and I am not sure. I am going to leave the code below. The commented out section wasn't relevant to my code but left it for reference. Any further help as to why the table isn't loading would be helpful!

class MyCookbookVC : PFQueryTableViewController {

  override init!(style: UITableViewStyle, className: String!) {
    super.init(style: style, className: className)
    textKey = "Name"
    pullToRefreshEnabled = true
    paginationEnabled = true
    objectsPerPage = 25
  }

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

  override func viewDidLoad() {

    tableView.reloadData()

  }

  override func queryForTable() -> PFQuery! {
    let query = PFUser.query()
    query.whereKey("CreatedBy", equalTo: PFUser.currentUser())
    query.orderByAscending("Name")

    //if network cannot find any data, go to cached (local disk data)
    if (self.objects.count == 0){
      query.cachePolicy = kPFCachePolicyCacheThenNetwork
    }

    return query
  }

  override func tableView(tableView: UITableView!, cellForRowAtIndexPath   indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PFTableViewCell
    cell.textLabel?.text = object["Name"] as? String

    /*if let profileImage = object["profileImage"] as? PFFile {
      cell.imageView.file = profileImage
    }
    else {
      cell.imageView.image = kProfileDefaultProfileImage
    }
    cell.imageView.layer.cornerRadius = cell.imageView.frame.size.width / 2;
    cell.imageView.clipsToBounds = true
    cell.imageView.layer.borderWidth = 3.0
    cell.imageView.layer.borderColor = UIColor.whiteColor().CGColor */


   /* cell.textLabel?.font = UIFont(name: kStandardFontName, size: kStandardFontSize)
    cell.textLabel?.textColor = UIColor.whiteColor()
    cell.backgroundColor = kbackgroundColor */

    return cell
  }
} 
Olyve
  • 701
  • 1
  • 8
  • 27
  • Please show your Swift code and explain which specific issues you have encountered. – Michał Ciuba Feb 19 '15 at 17:02
  • The code at this point is irrelevant, I am asking for help finding a resource or someone to show an example of how to use PFQueryTableView in swift with possibly an explanation – Olyve Feb 19 '15 at 17:28
  • 1
    Unfortunately, questions asking for a tutorial or other resources are considered off-topic on Stack Overflow, as explained here: http://stackoverflow.com/help/on-topic. You have already done some work, please show us the results. Maybe someone else will have a problem similar to yours and the answer for this specific question will help them. – Michał Ciuba Feb 19 '15 at 17:31
  • Some quick google searches showed [me](http://stackoverflow.com/a/28618968/4080860) [these](https://groups.google.com/forum/#!topic/parse-developers/jh0TZpZxA_w) [sites](http://stackoverflow.com/questions/25069921/use-pfquerytableviewcontroller-from-parse-with-swift). – hhanesand Feb 20 '15 at 02:14
  • Can you implement objectsDidLoad: and add print(error). What is the output when that is run? Or does nothing get printed? – mverderese Mar 16 '15 at 02:17

3 Answers3

1

Your query is querying PFUser when it should it be querying your "Recipe" class. Change this line

let query = PFUser.query()

to

let query = PFQuery.queryWithClassName("Recipe")

mverderese
  • 5,314
  • 6
  • 27
  • 36
0

I posted my working solution in the Parse Google Group. Maybe it will help you. https://groups.google.com/forum/#!topic/parse-developers/XxLjxX29nuw

ericgu
  • 2,229
  • 23
  • 25
  • 1
    I tried using your code and it has helped me quite a bit, but my table does not pull any data from parse or load it. Any ideas as to why it would appear with the loading thing spinning away and then load nothing, even tried the pull down to refresh nothing happens. – Olyve Mar 13 '15 at 15:23
  • Did you go through Parse QuickStart and do the Foo Bar test to ensure your environment is set up correctly? – ericgu Mar 13 '15 at 15:24
  • Yes I have used Parse for other things, I just can't figure out why the query isn't returning data. I have added the data personally to the database – Olyve Mar 13 '15 at 17:22
0

You're using PFUser.query() which is useful for querying for users, but you want to use PFQuery(className: YOUR_PARSE_CLASS)

Austin
  • 1,087
  • 3
  • 14
  • 27