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 {
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
}
......
......@@ -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() {
......
......@@ -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) {
......
......@@ -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..<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)")
array = manager.fetchFavorites()
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
}
extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> 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:
......
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