Commit 64307c70 by Julio Hermosa

Se corrige error al obtener la información de algunos pedidos (por campos…

Se corrige error al obtener la información de algunos pedidos (por campos nulos, se cambia a opcional la variable picture en el struct )
parent 574b8ff0
...@@ -42,7 +42,7 @@ struct Request: Codable { ...@@ -42,7 +42,7 @@ struct Request: Codable {
let title, message, name, phone: String let title, message, name, phone: String
let address, city: String let address, city: String
let location: Location let location: Location
let picture: String let picture: String?
let active: Bool let active: Bool
let added: String let added: String
} }
......
...@@ -22,6 +22,7 @@ class MapViewController: UIViewController { ...@@ -22,6 +22,7 @@ class MapViewController: UIViewController {
let format:Format = Format.init() let format:Format = Format.init()
var bbox = String() var bbox = String()
var id = Int() var id = Int()
var favorites = [Entity]()
let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609) let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609)
//-57.5879897,-43.2723609 -> Posición de Roshka //-57.5879897,-43.2723609 -> Posición de Roshka
...@@ -138,14 +139,14 @@ class MapViewController: UIViewController { ...@@ -138,14 +139,14 @@ class MapViewController: UIViewController {
let long = features[i].geometry.coordinates[0] let long = features[i].geometry.coordinates[0]
self.id = features[i].properties.pk self.id = features[i].properties.pk
let position = CLLocationCoordinate2D(latitude: lat, longitude: long) let position = CLLocationCoordinate2D(latitude: lat, longitude: long)
let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 24, height: 30)) let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35))
let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 30)) let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 35))
markerView.addSubview(markerButton)
markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside) markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside)
let pin = self.addPins(id: self.id) 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) let marker = GMSMarker(position: position)
marker.map = self.mapView marker.map = self.mapView
marker.iconView = markerView marker.iconView = markerView
marker.title = "\(features[i].properties.pk)" marker.title = "\(features[i].properties.pk)"
...@@ -173,15 +174,30 @@ class MapViewController: UIViewController { ...@@ -173,15 +174,30 @@ class MapViewController: UIViewController {
} }
//Verificamos si el marcador corresponde a un favorito y agregamos la imagen correspondiente //Verificamos si el marcador corresponde a un favorito y agregamos la imagen correspondiente
func addPins(id: Int)->UIImage{ func addPins(id: Int)->String{
let array = manager.fetchFavorites() //let array = manager.fetchFavorites()
var pinImage = UIImage(named: "pinGMAPS") var named = String()
for i in 0 ..< array.count{ if favorites.count > 0{
if array[i].id == Int64(id) { for i in 0 ..< favorites.count{
pinImage = UIImage(named: "pinFavGMAPS") 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()
} }
......
...@@ -19,22 +19,11 @@ class MyPendingsTableViewCell: UITableViewCell { ...@@ -19,22 +19,11 @@ class MyPendingsTableViewCell: UITableViewCell {
@IBOutlet weak var monthLabel: UILabel! @IBOutlet weak var monthLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var detailLabel: 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() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
dayLabel.textColor = format.subTitleTextColor dayLabel.textColor = format.subTitleTextColor
monthLabel.textColor = format.titleTextColor monthLabel.textColor = format.titleTextColor
} }
override func setSelected(_ selected: Bool, animated: Bool) { override func setSelected(_ selected: Bool, animated: Bool) {
......
...@@ -9,44 +9,35 @@ ...@@ -9,44 +9,35 @@
import UIKit import UIKit
import CoreData 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 { class PendingsViewController: UIViewController {
let manager = CoreDataManager() let manager = CoreDataManager()
var array = [Entity]() var array = [Entity]()
var myPendings = [MyPendings]()
let format = Format.init() let format = Format.init()
@IBOutlet weak var tableView: UITableView! @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) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
array = manager.fetchFavorites() array = manager.fetchFavorites()
// for i in 0..<manager.fetchFavorites().count {
// myPendings.append(MyPendings(id: Int(array[i].id), title: array[i].title, message: array[i].message, date: array[i].date, address: array[i].address, contactNumber: array[i].name, contactName: array[i].phoneNumber))
// }
// print("Mis pendintes\(myPendings)")
} }
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
tableView.delegate = self tableView.delegate = self
tableView.dataSource = self tableView.dataSource = self
} }
} }
extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
...@@ -97,6 +88,10 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -97,6 +88,10 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
headerLabel.addSubview(heartImage) headerLabel.addSubview(heartImage)
return headerLabel 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) { func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
switch editingStyle { switch editingStyle {
case .delete: case .delete:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment