How do I create a PFQueryTableViewController using Parse in Swift?

I imported all the required frameworks, but from now on I don't really know what to do (I'm new to Swift and have absolutely nothing about Objective C). The analysis docs are not in Swift, but can someone point me to a starting point?

I have initialized my view controller (which does not appear when the app starts, I just get a black screen, but based on this video I should see a table: https://parse.com/tutorials/parse-query-table )

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    //Link to Parse
    Parse.setApplicationId("...", clientKey: "...")

    var controller:PFQueryTableViewController = PFQueryTableViewController(className: "test1")
    self.window?.rootViewController = controller
    self.window?.makeKeyAndVisible()

    return true

      

+3


source to share


2 answers


Make sure you have imported all SDK parsing options Create 2 new cocoa touch class, inject one of the PFQueryTableViewController subclasses and the other PFTableViewCell. Pick them up on your storyboards. Make sure the Tableview and cell are pointing to these files. Your Tableview file should look something like this:

import UIKit

class YourTableViewController: 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.parseClassName = "yourClass"

    self.textKey = "yourObject"
    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: "yourClass")
    query.orderByAscending("yourObject")


    return query
}

//override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFTableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as CustomTableViewCell!
    if cell == nil {
        cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
    }

    // Extract values from the PFObject to display in the table cell

    cell.info.text = object["info"] as String


    // Date for cell subtitle
    var dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd"
    let dateForText = object["date"] as NSDate
    cell.date.text = dateFormatter.stringFromDate(dateForText)







    return cell
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using [segue destinationViewController].
    var detailScene = segue.destinationViewController as YourDetailViewController

    // Pass the selected object to the destination view controller.
    if let indexPath = self.tableView.indexPathForSelectedRow() {
        let row = Int(indexPath.row)
        detailScene.currentObject = objects[row] as? PFObject
    }
}


Make sure you have set the cells reuse identifier to match what you are setting it to in this code. 

      



When I call cell.info, cell.date. These are IBOutlets that I have set in my CustomTableViewCell file.

class CustomTableViewCell: PFTableViewCell {

@IBOutlet weak var info: UILabel!
@IBOutlet weak var date: UILabel!
@IBOutlet weak var mixCoverPhotoImageView: PFImageView!




}

      

+12


source


I am processing an image using the Alamofireimage frame. The function is really simple.



Alamofire.request(myURL).responseImage(completionHandler: { (response) in
            if let ThumbImage = response.result.value {
                DispatchQueue.main.async{
                cell?. mixCoverPhotoImageView?.image = ThumbImage
            }

      

0


source







All Articles