Last active
August 29, 2015 14:23
-
-
Save 3lvis/7faa0d01b0ea9a5dfe69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import XCPlayground | |
func table() -> UITableView { | |
let frame = CGRect(x: 0, y: 0, width: 320.0, height: 320.0) | |
let tableView = UITableView(frame: frame) | |
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") | |
return tableView | |
} | |
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
var tableView: UITableView! | |
let items = ["Hello 1", "Hello 2", "Hello 3"] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.frame = CGRect(x: 0, y: 0, width: 320, height: 320) | |
self.tableView = table() | |
self.tableView!.dataSource = self | |
self.view.addSubview(self.tableView) | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ | |
return self.items.count; | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ | |
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell | |
cell.textLabel?.text = "\(self.items[indexPath.row])" | |
return cell | |
} | |
} | |
var ctrl = ViewController() | |
XCPShowView("Playground VC", ctrl.view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment