From 64307c705a1daf20a33ac08e324d3e0725e1248d Mon Sep 17 00:00:00 2001 From: Julio Hermosa Date: Mon, 18 May 2020 19:00:22 -0400 Subject: [PATCH] Se corrige error al obtener la información de algunos pedidos (por campos nulos, se cambia a opcional la variable picture en el struct ) --- ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate | Bin 164367 -> 0 bytes ayudapy/Api/HelpRequest.swift | 2 +- ayudapy/Base.lproj/Main.storyboard | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- ayudapy/ViewControllers/MapViewController.swift | 40 ++++++++++++++++++++++++++++------------ ayudapy/ViewControllers/MyPendingsTableViewCell.swift | 11 ----------- ayudapy/ViewControllers/PendingsViewController.swift | 39 +++++++++++++++++---------------------- 6 files changed, 100 insertions(+), 69 deletions(-) diff --git a/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate b/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate index 767afab..7a350ef 100644 Binary files a/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate and b/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ayudapy/Api/HelpRequest.swift b/ayudapy/Api/HelpRequest.swift index ddd7695..0381cc9 100644 --- a/ayudapy/Api/HelpRequest.swift +++ b/ayudapy/Api/HelpRequest.swift @@ -42,7 +42,7 @@ struct Request: Codable { let title, message, name, phone: String let address, city: String let location: Location - let picture: String + let picture: String? let active: Bool let added: String } diff --git a/ayudapy/Base.lproj/Main.storyboard b/ayudapy/Base.lproj/Main.storyboard index d5a5790..6388552 100644 --- a/ayudapy/Base.lproj/Main.storyboard +++ b/ayudapy/Base.lproj/Main.storyboard @@ -32,47 +32,51 @@ + - + - + - + - + - + - - + + - + - - - - + + + + + + + + + - + + - + @@ -135,14 +150,13 @@ - - + @@ -201,7 +215,24 @@ - + + + + + + + + + + + + + + + + + + diff --git a/ayudapy/ViewControllers/MapViewController.swift b/ayudapy/ViewControllers/MapViewController.swift index 2cae8d9..0e88e6b 100644 --- a/ayudapy/ViewControllers/MapViewController.swift +++ b/ayudapy/ViewControllers/MapViewController.swift @@ -22,6 +22,7 @@ class MapViewController: UIViewController { let format:Format = Format.init() var bbox = String() var id = Int() + var favorites = [Entity]() let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609) //-57.5879897,-43.2723609 -> Posición de Roshka @@ -138,14 +139,14 @@ class MapViewController: UIViewController { let long = features[i].geometry.coordinates[0] self.id = features[i].properties.pk let position = CLLocationCoordinate2D(latitude: lat, longitude: long) - let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 24, height: 30)) - let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 30)) - markerView.addSubview(markerButton) + let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) + let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside) let pin = self.addPins(id: self.id) - markerButton.setImage(pin, for: .normal) + print("Nombre\(pin)") + markerButton.setImage(UIImage(named: pin), for: .normal) + markerView.addSubview(markerButton) let marker = GMSMarker(position: position) - marker.map = self.mapView marker.iconView = markerView marker.title = "\(features[i].properties.pk)" @@ -173,16 +174,31 @@ class MapViewController: UIViewController { } //Verificamos si el marcador corresponde a un favorito y agregamos la imagen correspondiente - func addPins(id: Int)->UIImage{ - let array = manager.fetchFavorites() - var pinImage = UIImage(named: "pinGMAPS") - for i in 0 ..< array.count{ - if array[i].id == Int64(id) { - pinImage = UIImage(named: "pinFavGMAPS") + func addPins(id: Int)->String{ + //let array = manager.fetchFavorites() + var named = String() + if favorites.count > 0{ + for i in 0 ..< favorites.count{ + if favorites[i].id == Int64(id) { + print("es favorito") + named = "pinFavGMAPS" } + else { + print("no es favorito") + named = "pinGMAPS" + } } - return pinImage! + } + else{ + named = "pinGMAPS" + } + + return named } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(true) + favorites = manager.fetchFavorites() + } override func viewDidLoad() { diff --git a/ayudapy/ViewControllers/MyPendingsTableViewCell.swift b/ayudapy/ViewControllers/MyPendingsTableViewCell.swift index 1879642..507f7da 100644 --- a/ayudapy/ViewControllers/MyPendingsTableViewCell.swift +++ b/ayudapy/ViewControllers/MyPendingsTableViewCell.swift @@ -19,22 +19,11 @@ class MyPendingsTableViewCell: UITableViewCell { @IBOutlet weak var monthLabel: UILabel! @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var detailLabel: UILabel! - @IBOutlet weak var deleteButton: UIButton! -// @IBAction func deleteRow(_ sender: Any) { -// array = manager.fetchFavorites() -// print(id) -// manager.deleteFavorites(id: id, array: array) -// } - - - override func awakeFromNib() { super.awakeFromNib() dayLabel.textColor = format.subTitleTextColor monthLabel.textColor = format.titleTextColor - - } override func setSelected(_ selected: Bool, animated: Bool) { diff --git a/ayudapy/ViewControllers/PendingsViewController.swift b/ayudapy/ViewControllers/PendingsViewController.swift index 6c2b8ac..2a274eb 100644 --- a/ayudapy/ViewControllers/PendingsViewController.swift +++ b/ayudapy/ViewControllers/PendingsViewController.swift @@ -9,44 +9,35 @@ import UIKit import CoreData -struct MyPendings{ - var id: Int - - var title: String? - var message: String? - var date: String? - var address: String? - var contactNumber: String? - var contactName: String? -} - class PendingsViewController: UIViewController { - - let manager = CoreDataManager() var array = [Entity]() - var myPendings = [MyPendings]() let format = Format.init() @IBOutlet weak var tableView: UITableView! + func goToRequestViewController(pk: Int){ + let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController + pedidosVC.id = pk + print("ID del pedido: \(pk)") + pedidosVC.helpRequest() + //show(pedidosVC, sender: nil) + present(pedidosVC, animated: true, completion: nil) + } + + + + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - array = manager.fetchFavorites() - -// for i in 0.. Int { @@ -97,6 +88,10 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ headerLabel.addSubview(heartImage) return headerLabel } + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + goToRequestViewController(pk: Int(array[indexPath.row].id)) + } + func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { switch editingStyle { case .delete: -- libgit2 0.26.0