@@ -502,55 +502,55 @@ The easiest way to understand this class is with an example. This subclass of `P
502
502
@end
503
503
```
504
504
``` 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
+ }
525
514
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
+ }
531
522
532
- query.orderByDescending (" createdAt" )
523
+ override func queryForTable () -> PFQuery<PFObject> {
524
+ let query = PFQuery (className : self .parseClassName ! )
533
525
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
535
530
}
536
531
537
- override func tableView (tableView : UITableView, cellForRowAtIndexPath indexPath : NSIndexPath, object : PFObject? ) -> PFTableViewCell? {
538
- let cellIdentifier = " cell"
532
+ query.order (byDescending : " createdAt" )
539
533
540
- var cell = tableView.dequeueReusableCellWithIdentifier (cellIdentifier) as? PFTableViewCell
541
- if cell == nil {
542
- cell = PFTableViewCell (style : .Subtitle , reuseIdentifier : cellIdentifier)
543
- }
534
+ return query
535
+ }
544
536
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"
551
539
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)) "
553
550
}
551
+
552
+ return cell
553
+ }
554
554
}
555
555
```
556
556
</div >
@@ -586,21 +586,21 @@ A good starting point to learn more is to look at the [API for the class](http:/
586
586
@end
587
587
```
588
588
``` 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"
591
591
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
+ }
596
596
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
+ }
602
602
603
- return cell
603
+ return cell
604
604
}
605
605
```
606
606
</div >
0 commit comments