Created
August 30, 2014 19:11
-
-
Save benvium/f6dfa10ebf5c5d5f6ed1 to your computer and use it in GitHub Desktop.
Minimal Swift TableViewController with very basic datasource from a literal array
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
class MyCellSubclass: UITableViewCell { | |
@IBOutlet var myNameLabel: UILabel!; | |
@IBOutlet var myOtherLabel: UILabel!; | |
// Do not include any inits, or we need to implement | |
// the required init outself | |
// http://stackoverflow.com/questions/25126295/swift-class-does-not-implement-its-superclasss-required-members | |
} |
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 | |
class ViewController: UITableViewController { | |
let data = [ | |
[ "a":"foo", "b":"bar"], | |
[ "a":"foo2", "b":"bar2"], | |
[ "a":"foo3", "b":"bar3"], | |
[ "a":"foo4", "b":"bar4"] | |
]; | |
// ! are only really there because it's an Obj-C API (implicity unwrapped optionals) | |
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { | |
var cell = tableView.dequeueReusableCellWithIdentifier("MyCellSubclass") as MyCellSubclass; | |
cell.myNameLabel.text = data[indexPath.row]["a"]; | |
cell.myOtherLabel.text = data[indexPath.row]["b"]; | |
return cell; | |
} | |
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { | |
return data.count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment