Делегат MapView, возвращающий ноль - PullRequest
0 голосов
/ 28 августа 2018

Я делаю приложение, которое вводит один адрес в один ViewController, и этот адрес идет в MapView в другом ViewController и добавляет аннотацию. Но когда я добавляю адрес, когда возвращаюсь к просмотру карты, приложение вылетает и показывает, что мой mapview.delegate равен нулю. Вот мой код для ввода адреса:

 @IBAction func createButtonPressed(_sender: Any) {

            guard let address = addresTxtFd.text else { return }
            guard let date = dateTxtFd.text else { return }
            let geocoder = CLGeocoder()
            geocoder.geocodeAddressString((address)) { (placemarks, error) in
                if error == nil {
                    if let placemark = placemarks?[0] {
                        let location = placemark.location!
                        let latitude = location.coordinate.latitude
                        let longitude = location.coordinate.longitude
                        self.locatinService.setLocation(address: address, date: date, latidude: latitude, longitude: longitude, completion: { (success) in
                            if success {
                                let map = MapVC()
                                map.modalPresentationStyle = .custom
                                self.present(map, animated: true, completion: nil)
    //                             LocationServices().dropPin()
                            }
                        })
                    }
                }
            }

Вот мой обзор карты:

class MapVC: UIViewController {

//    Outlets
    @IBOutlet weak var mapView: MKMapView!
    @IBOutlet weak var newGSButton: UIButton!
//    Variables

    var locationManager = CLLocationManager()
    var locationAuthorization = CLLocationManager.authorizationStatus()

    var regionRadius: Double = 1000

    let annotations = MKPointAnnotation()


    override func viewDidLoad() {
        super.viewDidLoad()
        mapView.delegate = self
        locationManager.delegate = self
        configureCurrentLocation()
    }

    @IBAction func centerUserLocation(_ sender: Any) {
       centerUserCurrentLocation()
    }

    @IBAction func newGSButtonPressed(_ sender: Any) {
        if AuthService.instance.isLoggedIn
        {
            let newGs = NewGarageSaleVC()
            newGs.modalPresentationStyle = .custom
            present(newGs, animated: true, completion: nil)
        } else {
            performSegue(withIdentifier: TO_LOGIN, sender: nil)
        }
    }

}

А вот и ошибка:

Тема 1: Неустранимая ошибка: неожиданно обнаружен ноль при развертывании Необязательное значение

Спасибо всем.

...