Skip to content

Update swift code snippets for PFQueryTableViewController #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions _includes/ios/user-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,55 +502,55 @@ The easiest way to understand this class is with an example. This subclass of `P
@end
```
```swift
class SimpleTableViewController : PFQueryTableViewController {

override init(style: UITableViewStyle, className: String?) {
super.init(style: style, className: className)
parseClassName = "Todo"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
parseClassName = "Todo"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}

override func queryForTable() -> PFQuery {
let query = PFQuery(className: self.parseClassName!)
class SimpleTableViewController: PFQueryTableViewController {

override init(style: UITableView.Style, className: String?) {
super.init(style: style, className: className)
parseClassName = "Todo"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}

// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if self.objects!.count == 0 {
query.cachePolicy = .CacheThenNetwork
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
parseClassName = "Todo"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}

query.orderByDescending("createdAt")
override func queryForTable() -> PFQuery<PFObject> {
let query = PFQuery(className: self.parseClassName!)

return query
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if self.objects!.count == 0 {
query.cachePolicy = .cacheThenNetwork
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let cellIdentifier = "cell"
query.order(byDescending: "createdAt")

var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? PFTableViewCell
if cell == nil {
cell = PFTableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
}
return query
}

// Configure the cell to show todo item with a priority at the bottom
if let object = object {
cell!.textLabel?.text = object["text"] as? String
let priority = object["priority"] as? String
cell!.detailTextLabel?.text = "Priority \(priority)"
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let cellIdentifier = "cell"

return cell
var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as? PFTableViewCell
if cell == nil {
cell = PFTableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
}

// Configure the cell to show todo item with a priority at the bottom
if let object = object {
cell!.textLabel?.text = object["text"] as? String
let priority = object["priority"] as? String
cell!.detailTextLabel?.text = "Priority \(String(describing: priority))"
}

return cell
}
}
```
</div>
Expand Down Expand Up @@ -586,21 +586,21 @@ A good starting point to learn more is to look at the [API for the class](http:/
@end
```
```swift
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let identifier = "cell"
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let identifier = "cell"

var cell = tableView.dequeueReusableCellWithIdentifier(identifier) as? PFTableViewCell
if cell == nil {
cell = PFTableViewCell(style: .Default, reuseIdentifier: identifier)
}
var cell = tableView.dequeueReusableCell(withIdentifier: identifier) as? PFTableViewCell
if cell == nil {
cell = PFTableViewCell(style: .default, reuseIdentifier: identifier)
}

if let object = object {
cell?.textLabel?.text = object["title"] as? String
cell?.imageView?.image = UIImage(named: "placeholder.jpg")
cell?.imageView?.file = object["thumbnail"] as? PFFileObject
}
if let object = object {
cell?.textLabel?.text = object["title"] as? String
cell?.imageView?.image = UIImage(named: "placeholder.jpg")
cell?.imageView?.file = object["thumbnail"] as? PFFileObject
}

return cell
return cell
}
```
</div>
Expand Down