无法识别的选择器发送到实例..对于MapView委托,“NSInvalidArgumentException”

时间:2018-02-25 22:13:07

标签: ios swift google-maps

Swift 4 /谷歌地图。

我得到的崩溃是......

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:' - [UIView setDelegate:]:   无法识别的选择器发送到实例0x7fa1eb50d7e0'

是的,我知道这里有一些很多的线程,但是通过它们查看并没有帮助我。我已经调试了很多我怀疑的地方,但不确切知道如何解决。

Here's the git repo

一些细节.. MapViewController有三个UIViews。

  • 的MapViewController
  • 主视图(控制器附带的默认视图) - 菜单(主视图的子视图) - 地图(主视图的子视图)

我相信我已经将崩溃缩小到声明

self.mapView.delegate = self

这是MapViewController的大部分代码。

import UIKit
import GoogleMaps
import FirebaseDatabase

class MapViewController: UIViewController, GMSMapViewDelegate, CLLocationManagerDelegate {
    @IBOutlet var mapView: GMSMapView!

    var locationOfInterestMarker = GMSMarker()
    var userMarker = GMSMarker()
    var locationManager = CLLocationManager()
    let zoom:Float = 15
    let locationOfInterestImage:String = "hhouseicon"
    let userMarkerImage:String = "witchicon"


    override func viewDidLoad() {
        super.viewDidLoad()
        self.getLocations()
        self.locationManager.delegate = self
        self.locationManager.requestAlwaysAuthorization()
        self.locationManager.requestWhenInUseAuthorization()
        self.locationManager.startMonitoringSignificantLocationChanges()
        /**
                The next line causes crash.  I believe I need to set the delegate to something other than self.  Set the delegate to the View named Map.  However I'm not sure about the actual code for that.
         **/
        self.mapView.delegate = self //Crashes
    }

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        guard status == .authorizedWhenInUse else {
            return
        }
        self.locationManager.startUpdatingLocation()
        self.mapView.isMyLocationEnabled = true
        self.mapView.settings.myLocationButton = true
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard let location = locations.first else {
            return
        }
        self.locationManager.stopUpdatingLocation()
        self.mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
        self.placeMarker(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude, marker: self.userMarker, imageName: userMarkerImage)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?){
        if let destination = segue.destination as? LocationDetialViewController {
        destination.coordinate = locationManager.location?.coordinate
        } else {
            return
        }
    } . . .
     func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
            performSegue(withIdentifier: "locationDetailSegue", sender: self)
            return false
        }

    }//MapViewController

1 个答案:

答案 0 :(得分:1)

查看您的代码和故事板后。 我可以看到你已连接

@IBOutlet var mapView: GMSMapView!

对于父视图而不是实际的GMSMapView所以请重新检查IBOutlet连接。

enter image description here

enter image description here