Skip to content

Instantly share code, notes, and snippets.

@fisherds
Last active January 2, 2018 17:24
Show Gist options
  • Select an option

  • Save fisherds/e312bfda45fd89b7a160 to your computer and use it in GitHub Desktop.

Select an option

Save fisherds/e312bfda45fd89b7a160 to your computer and use it in GitHub Desktop.
Code used in the video to implement StudentTableViewController in the First Day Demo
import UIKit
class StudentTableViewController: UITableViewController {
let students = ["Nick", "Trevor", "Joseph", "Ruying", "Zhiyang", "Chris", "Jonathan", "Matt", "Tayler", "Jonathan", "Matt", "Jonathan", "Haolin", "Anthony", "Tianjiao", "Chris", "Bo", "Ashok", "Philip", "Grant", "Ishank", "Stephen", "Benedict", "Xiangqing"]
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return students.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "studentCell", for: indexPath)
cell.textLabel?.text = students[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let ac = UIAlertController(title: "You clicked on... \(students[indexPath.row])", message: nil, preferredStyle: UIAlertControllerStyle.alert)
ac.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
present(ac, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment