Guest User

Untitled

a guest
Jan 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import UIKit
  2. import Firebase
  3. import FirebaseDatabase
  4.  
  5. class sons {
  6. let name : String!
  7. //let place : String!
  8.  
  9. init(title_String : String!){
  10.  
  11. self.name = title_String
  12. // self.place = place_String
  13. }
  14. }
  15.  
  16. class sonsTableViewController: UITableViewController {
  17.  
  18. var ref:DatabaseReference!
  19.  
  20. //var sons = [String]()
  21. var newSon: String = ""
  22. let cellId = "cellId"
  23. var refHandel : uint!
  24. var sonsList = [sons]()
  25.  
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28.  
  29.  
  30. ref = Database.database().reference()
  31. ref.child("name").queryOrderedByKey().observeSingleEvent(of: .childAdded, with: { snapshot in
  32.  
  33. let value = snapshot.value as? NSDictionary
  34. let name = value!["name"] as! String
  35. self.sonsList.append(sons(title_String : name))
  36. self.tableView.reloadData()
  37.  
  38. })
  39.  
  40. //fetchName()
  41.  
  42. }
  43.  
  44. func fetchName() {
  45.  
  46. }
  47.  
  48.  
  49. @IBAction func cancel(segue:UIStoryboardSegue) {
  50.  
  51.  
  52. }
  53.  
  54. @IBAction func done(segue:UIStoryboardSegue) {
  55.  
  56. var sonDetailVC = segue.source as! addSonViewController
  57. newSon = sonDetailVC.name
  58. // sons.append(newSon)
  59. }
  60.  
  61. override func didReceiveMemoryWarning() {
  62. super.didReceiveMemoryWarning()
  63. }
  64.  
  65. override func numberOfSections(in tableView: UITableView) -> Int {
  66. return 1
  67. }
  68.  
  69. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  70. return sonsList.count
  71. }
  72.  
  73.  
  74. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  75.  
  76. var cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
  77. let label = cell?.viewWithTag(1) as! UILabel
  78. label.text = sonsList[indexPath.row].name
  79.  
  80. return cell!
  81. }
Add Comment
Please, Sign In to add comment