How to Create a Pfquerytableviewcontroller with Parse in Swift

Use PFQueryTableViewController (from parse) with Swift

You need to initialize the ViewController. As a test, initialize it in your appdelegate like this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("YOUR_APP_ID", clientKey:"YOUR_CLIENT_KEY")
var controller:PFQueryTableViewController = PFQueryTableViewController(className: "YOUR_PARSE_CLASS_NAME")
self.window?.rootViewController = controller
return true
}

Here is my PFQUeryTableViewController

class TestTableViewController: PFQueryTableViewController {

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

override init(className aClassName: String!) {
super.init(className: aClassName)

self.parseClassName = aClassName
self.textKey = "YOUR_PARSE_COLOMN_YOU_WANT_TO_SHOW"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
}

Hope this helps, let me know if you have any questions. Note, we need to pass in a class name in the initializer for this class. We pass that class name in the appdelegate here, but when we add this view to another controller, we would pass in the class name there instead. This was more to get you up and running

Swift and Parse - PFQueryTableViewController loadingViewEnabled

Only the table controller is unique to Parse. The spinner is just a regular UI element. Thus, the iOS developer references are good places to look for this.

Try this link for the activity spinner:

This link shows information about the controller, which shows that it simply inherits from UITableViewController, and the cells/background can be styled accordingly.

In general, Parse tries to prefix its objects with PF.

PFQueryTableViewController in swift not loading data

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")

in Parse.com, how to use query.includeKey in PFQueryTableViewController with swift?

After I got an inspiration from @deadbeef (see answer 1), here is the solution I got :

  1. query.includeKey("pointerToDetails") is querying an object which can be accessed via object["pointerToDetails"].

  2. to extract data from column detailText which already included in object["pointerToDetails"], just do this :


if let pointer = object["pointerToDetails"] as? PFObject {
cell.detail.text = object["detailText"] as String!
}

here is the whole code :

import UIKit

class TableViewController: PFQueryTableViewController {

// Initialise the PFQueryTable tableview
override init!(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}

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

// Configure the PFQueryTableView
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}

// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery! {

var query = PFQuery(className: "Places")
query.includeKey("pointerToDetails")
return query
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as CustomTableViewCell!
if cell == nil {
cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CustomCell")
}

// Extract values from the PFObject to display in the table cell
cell.name.text = object["placeText"] as String!
if let pointer = object["pointerToDetails"] as? PFObject {
cell.detail.text = object["detailText"] as String!
}
return cell
}
}

ParseUI PFQueryTableViewController in SWIFT

Make sure the ViewController you are setting to ClubDetailsViewController is a UITableViewController and not a UIViewController.

PFQueryTableViewController is a subclass of UITableViewController that in turn is a subclass of UIViewController. For your ViewController to conform to the UITableViewController it needs to follow certain rules like having a UITableView and not having other subviews. When you drag a UITableViewController onto your storyboard it makes sure it follows the needed rules.

PFQueryTableView with multiple sections (Swift + Parse.com)

So for anyone trying to do this, I found a BRILLIANT solution! Best part about it? ZERO CODE required!

I stumbled upon this other question in StackOverflow (UITableView Mix of Static and Dynamic Cells?) and found that the bottom answer of using a Container View at the top of the UITableViewController works the same for PFQueryTableViewController!

This web page gives further detail on how to do this step-by-step:

http://www.mikebobiney.com/2014/09/28/static-table-view-containers/



Related Topics



Leave a reply



Submit