Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import UIKit
  2. import FirebaseAuth
  3. import FirebaseDatabase
  4.  
  5. class GastosViewController: UIViewController {
  6.  
  7. let idUser = Auth.auth().currentUser?.displayName
  8. var arrayGastos = [Gastos]()
  9.  
  10. @IBOutlet weak var tableView: UITableView!
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. tableView.delegate = self
  14. tableView.dataSource = self
  15. var ref : DatabaseReference
  16. ref = Database.database().reference().child("Users").child(idUser!).child("Gastos")
  17. ref.observe(.value) { (snapshot) in
  18. let value = snapshot.value as? NSDictionary
  19. for j in value!{
  20. let i = j.value as? NSDictionary
  21. let titulo = i?["Nombre"] as? String
  22. let descripcion = i?["Descripcion"] as? String
  23. let precio = i?["precio"] as? Float
  24. let fecha = i?["Fecha"] as? String
  25. let gastoAux = Gastos(titulo: titulo!, descripcion: descripcion!, precio: precio!, date: fecha!)
  26. print(titulo, descripcion, fecha, precio)
  27. self.arrayGastos.append(gastoAux)
  28. }
  29. }
  30.  
  31. // Do any additional setup after loading the view.
  32. }
  33.  
  34. }
  35.  
  36. extension GastosViewController : UITableViewDelegate, UITableViewDataSource{
  37.  
  38. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  39. return arrayGastos.count
  40. }
  41. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  42. let fila = arrayGastos[indexPath.row]
  43. let celda = tableView.dequeueReusableCell(withIdentifier: "CeldaGastos") as! Celda
  44.  
  45. celda.setCelda(celda: fila)
  46. return celda
  47. }
  48.  
  49. }
  50.  
  51. import Foundation
  52. import UIKit
  53. class Gastos{
  54.  
  55. var titulo : String
  56. var descripcion : String
  57. var precio : Float
  58. var date : String
  59.  
  60. init(titulo : String, descripcion : String, precio : Float, date : String) {
  61. self.titulo = titulo
  62. self.descripcion = descripcion
  63. self.precio = precio
  64. self.date = date
  65. }
  66.  
  67. }
  68.  
  69. import UIKit
  70.  
  71. class Celda: UITableViewCell {
  72.  
  73.  
  74.  
  75. @IBOutlet weak var Titulo: UILabel!
  76. @IBOutlet weak var Fecha: UILabel!
  77. @IBOutlet weak var Precio: UILabel!
  78. @IBOutlet weak var Descripcion: UILabel!
  79.  
  80. func setCelda(celda : Gastos){
  81. Titulo.text = celda.titulo
  82. Descripcion.text = celda.descripcion
  83. Fecha.text = celda.date
  84. Precio.text = String(celda.precio)
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement