Guest User

Untitled

a guest
Dec 14th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import UIKit
  2. class RoleTableViewController: UITableViewController {
  3.  
  4. var roles = [Role]()
  5.  
  6.  
  7.  
  8.  
  9.  
  10. //unwind
  11. @IBAction func unwindToRoleTableView(segue: UIStoryboardSegue) {
  12. if let controller = segue.source as? EditRoleTableViewController,
  13. let role = controller.role {
  14. roles.insert(role, at: 0)
  15. let indexPath = IndexPath(row: 0, section: 0)
  16. tableView.insertRows(at: [indexPath], with: .automatic)
  17. Role.saveToFile(roles: roles)
  18. }
  19. }
  20.  
  21.  
  22.  
  23. //show image and label& read on RoleTableView
  24.  
  25. override func viewDidLoad() {
  26.  
  27. if let roles = Role.readRolesFromFile() {
  28. self.roles = roles
  29.  
  30.  
  31. }
  32.  
  33. }
  34.  
  35. //dynamic count row of number
  36. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  37. // #warning Incomplete implementation, return the number of rows
  38. return roles.count
  39.  
  40.  
  41. }
  42.  
  43. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  44. let cell = tableView.dequeueReusableCell(withIdentifier: "roleCell", for: indexPath)
  45. let role = roles[indexPath.row]
  46. cell.textLabel?.text = role.name
  47.  
  48. return cell
  49. }
  50.  
  51.  
  52. }
Add Comment
Please, Sign In to add comment