Swift 4/谷歌地图。
我听到的是。。
由于意外异常而终止应用程序
“NSInvalidArgumentException”,原因:'-[UIView setDelegate:]:
无法识别的选择器发送到实例0x7fa1eb50d7e0'
是的,我知道这上面有很多线索,但仔细研究它们并没有帮助我。我已经调试了足够多的嫌疑人,但不知道如何解决。
Here's the git repo
一些细节。。MapViewController有三个uiview。
地图视图控制器
主视图(控制器附带的默认视图)
--菜单(主视图的子视图)
--地图(主视图的子视图)
我相信我已经把车祸的范围缩小到了

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

最佳答案

看了你的代码和故事板之后。
我可以看出你把
@IBOutlet var mapView: GMSMapView!
对于父视图而不是实际的GMSMapView,请重新检查IBOutlet连接。
ios - 无法识别的选择器已发送到实例。MapView委托(delegate)的“NSInvalidArgumentException”-LMLPHP
ios - 无法识别的选择器已发送到实例。MapView委托(delegate)的“NSInvalidArgumentException”-LMLPHP

关于ios - 无法识别的选择器已发送到实例。MapView委托(delegate)的“NSInvalidArgumentException”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48979052/

10-12 03:41