diff --git a/_includes/ios/user-interface.md b/_includes/ios/user-interface.md index d44c30cf7..57c480bf0 100644 --- a/_includes/ios/user-interface.md +++ b/_includes/ios/user-interface.md @@ -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 { + 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 + } } ``` @@ -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 } ```