Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3lvis/7faa0d01b0ea9a5dfe69 to your computer and use it in GitHub Desktop.
Save 3lvis/7faa0d01b0ea9a5dfe69 to your computer and use it in GitHub Desktop.
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