Skip to content

Commit b309b34

Browse files
authored
update PFQueryTableViewController code (#599)
1 parent e404a3d commit b309b34

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

_includes/ios/user-interface.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -502,55 +502,55 @@ The easiest way to understand this class is with an example. This subclass of `P
502502
@end
503503
```
504504
```swift
505-
class SimpleTableViewController : PFQueryTableViewController {
506-
507-
override init(style: UITableViewStyle, className: String?) {
508-
super.init(style: style, className: className)
509-
parseClassName = "Todo"
510-
pullToRefreshEnabled = true
511-
paginationEnabled = true
512-
objectsPerPage = 25
513-
}
514-
515-
required init?(coder aDecoder: NSCoder) {
516-
super.init(coder: aDecoder)
517-
parseClassName = "Todo"
518-
pullToRefreshEnabled = true
519-
paginationEnabled = true
520-
objectsPerPage = 25
521-
}
522-
523-
override func queryForTable() -> PFQuery {
524-
let query = PFQuery(className: self.parseClassName!)
505+
class SimpleTableViewController: PFQueryTableViewController {
506+
507+
override init(style: UITableView.Style, className: String?) {
508+
super.init(style: style, className: className)
509+
parseClassName = "Todo"
510+
pullToRefreshEnabled = true
511+
paginationEnabled = true
512+
objectsPerPage = 25
513+
}
525514

526-
// If no objects are loaded in memory, we look to the cache first to fill the table
527-
// and then subsequently do a query against the network.
528-
if self.objects!.count == 0 {
529-
query.cachePolicy = .CacheThenNetwork
530-
}
515+
required init?(coder aDecoder: NSCoder) {
516+
super.init(coder: aDecoder)
517+
parseClassName = "Todo"
518+
pullToRefreshEnabled = true
519+
paginationEnabled = true
520+
objectsPerPage = 25
521+
}
531522

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

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

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

540-
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? PFTableViewCell
541-
if cell == nil {
542-
cell = PFTableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
543-
}
534+
return query
535+
}
544536

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

552-
return cell
540+
var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as? PFTableViewCell
541+
if cell == nil {
542+
cell = PFTableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
543+
}
544+
545+
// Configure the cell to show todo item with a priority at the bottom
546+
if let object = object {
547+
cell!.textLabel?.text = object["text"] as? String
548+
let priority = object["priority"] as? String
549+
cell!.detailTextLabel?.text = "Priority \(String(describing: priority))"
553550
}
551+
552+
return cell
553+
}
554554
}
555555
```
556556
</div>
@@ -586,21 +586,21 @@ A good starting point to learn more is to look at the [API for the class](http:/
586586
@end
587587
```
588588
```swift
589-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
590-
let identifier = "cell"
589+
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
590+
let identifier = "cell"
591591

592-
var cell = tableView.dequeueReusableCellWithIdentifier(identifier) as? PFTableViewCell
593-
if cell == nil {
594-
cell = PFTableViewCell(style: .Default, reuseIdentifier: identifier)
595-
}
592+
var cell = tableView.dequeueReusableCell(withIdentifier: identifier) as? PFTableViewCell
593+
if cell == nil {
594+
cell = PFTableViewCell(style: .default, reuseIdentifier: identifier)
595+
}
596596

597-
if let object = object {
598-
cell?.textLabel?.text = object["title"] as? String
599-
cell?.imageView?.image = UIImage(named: "placeholder.jpg")
600-
cell?.imageView?.file = object["thumbnail"] as? PFFileObject
601-
}
597+
if let object = object {
598+
cell?.textLabel?.text = object["title"] as? String
599+
cell?.imageView?.image = UIImage(named: "placeholder.jpg")
600+
cell?.imageView?.file = object["thumbnail"] as? PFFileObject
601+
}
602602

603-
return cell
603+
return cell
604604
}
605605
```
606606
</div>

0 commit comments

Comments
 (0)