PFQueryTableViewController在迅速不加载数据 [英] PFQueryTableViewController in swift not loading data

查看:80
本文介绍了PFQueryTableViewController在迅速不加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,用于将数据从Parse加载到UITableView中.我使用了一些似乎可以将检索到的数据加载到表中的单元格中的代码,但这是有问题的,我进行了一些研究,找到了PFQueryTableViewController.这似乎是解决我的问题的方法,但是所有文档都在Objective-C中(我没有任何编码经验),也没有关于如何在Swift中使用该类的教程.有一些片段介绍了如何对其进行初始化,但是没有真正涉及如何在Swift中进行设置的内容.我试图浏览Obj-C文档,并在Swift中进行设置,但似乎无法正确完成,因此非常感谢您的帮助.没有人有建议的资源或有人设置了资源,可以逐步介绍如何在Swift中做到这一点?

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?

我找到了一些资源并尝试进行设置,表视图已加载,但是单元格中未加载任何内容,我不确定.我将在下面保留代码.注释掉的部分与我的代码无关,但留作参考.关于为何不加载该表的任何其他帮助将很有帮助!

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
  }
} 

推荐答案

您的查询在查询PFUser时应查询"Recipe"类.更改此行

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

let query = PFUser.query()

let query = PFQuery.queryWithClassName("Recipe")

这篇关于PFQueryTableViewController在迅速不加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆