From 67212c69b76e7e3647ccccfc254c4aef26e350ba Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 1 Feb 2016 11:04:39 -0800 Subject: [PATCH] Update Sample View Controller --- examples/Swift/Sample/AppDelegate.swift | 2 +- examples/Swift/Sample/ViewController.swift | 39 +++++++--------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/examples/Swift/Sample/AppDelegate.swift b/examples/Swift/Sample/AppDelegate.swift index a2b00b1727..3a1dac68c1 100644 --- a/examples/Swift/Sample/AppDelegate.swift +++ b/examples/Swift/Sample/AppDelegate.swift @@ -19,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let window = UIWindow(frame: UIScreen.mainScreen().bounds) window.backgroundColor = UIColor.whiteColor() - window.rootViewController = ViewController(nibName: nil, bundle: nil) + window.rootViewController = ViewController() window.makeKeyAndVisible() self.window = window return true diff --git a/examples/Swift/Sample/ViewController.swift b/examples/Swift/Sample/ViewController.swift index f907db6b93..4158103571 100644 --- a/examples/Swift/Sample/ViewController.swift +++ b/examples/Swift/Sample/ViewController.swift @@ -12,55 +12,40 @@ import UIKit import AsyncDisplayKit -class ViewController: UIViewController, ASTableViewDataSource, ASTableViewDelegate { +final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate { - var tableView: ASTableView + var tableNode: ASTableNode { + return node as! ASTableNode + } - - // MARK: UIViewController. - - override required init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { - self.tableView = ASTableView() - - super.init(nibName: nil, bundle: nil) - - self.tableView.asyncDataSource = self - self.tableView.asyncDelegate = self + init() { + super.init(node: ASTableNode()) + tableNode.delegate = self + tableNode.dataSource = self } required init?(coder aDecoder: NSCoder) { fatalError("storyboards are incompatible with truth and beauty") } - override func viewDidLoad() { - super.viewDidLoad() - self.view.addSubview(self.tableView) - } - - override func viewWillLayoutSubviews() { - self.tableView.frame = self.view.bounds - } - override func prefersStatusBarHidden() -> Bool { return true } - // MARK: ASTableView data source and delegate. - func tableView(tableView: ASTableView!, nodeForRowAtIndexPath indexPath: NSIndexPath!) -> ASCellNode! { - let patter = NSString(format: "[%ld.%ld] says hello!", indexPath.section, indexPath.row) + func tableView(tableView: ASTableView, nodeForRowAtIndexPath indexPath: NSIndexPath) -> ASCellNode { let node = ASTextCellNode() - node.text = patter as String + node.text = String(format: "[%ld.%ld] says hello!", indexPath.section, indexPath.row) return node } - func numberOfSectionsInTableView(tableView: UITableView!) -> Int { + func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } - func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { + func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 20 }