Last active
June 8, 2017 13:17
-
-
Save BayPhillips/0d000d7c720c2417405d to your computer and use it in GitHub Desktop.
A dumb Swift UIViewController with UITableView
This file contains hidden or 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 | |
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