Last active
January 2, 2018 17:24
-
-
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
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 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