Skip to content

Instantly share code, notes, and snippets.

@BayPhillips
Last active June 8, 2017 13:17
Show Gist options
  • Save BayPhillips/0d000d7c720c2417405d to your computer and use it in GitHub Desktop.
Save BayPhillips/0d000d7c720c2417405d to your computer and use it in GitHub Desktop.
A dumb Swift UIViewController with UITableView
import UIKit
class DumbViewController: UIViewController, UITableViewDataSource {
var items: [Int] = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.whiteColor()
(0...100).map({ items += value })
let tableView: UITableView = UITableView(frame: self.view.frame)
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.dataSource = self
self.view.addSubview(tableView)
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel.text = "\(items[indexPath.row])"
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment