Last active
August 29, 2015 14:26
-
-
Save oney/391ed921b3fb3b0ddf25 to your computer and use it in GitHub Desktop.
UITableViewDataSource
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
In ViewController | |
Add a UITableView to view of ViewController | |
connect UITableView to tableView property of ViewController | |
connect dataSource of UITableView to ViewController |
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: UIViewController, UITableViewDataSource { | |
var tableData: [String]! | |
@IBOutlet weak var tableView: UITableView? | |
let cellReuseIdentifier = "cellReuseIdentifier" | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) | |
tableData = ["foo", "bar", "kerker"] | |
tableView?.reloadData() | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return tableData!.count | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
var string = tableData[tableData!.count - indexPath.row - 1] | |
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as! UITableViewCell | |
cell.textLabel!.text = string | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment