I’m having trouble with the mapTypeChanged method in the WorldTrotter lesson (p. 115). I get errors at each case, specifically “Use of unresolved identifier ‘mapView’.” The code is below.
I don’t know how to fix this problem. Part of the problem is that I don’t understand the syntax. I think self (the first parameter of addTarget) is referring to the instance of MapViewController where this code is defined. The variable mapView is defined in the loadView method.
I am stymied by #selector.
I am 99% sure I have typed in the code exactly as directed in the book. Can anyone help me out?
Here is the line of code that uses the method, from the loadView method that I am overriding:
segmentedControl.addTarget(self, action: #selector(MapViewController.mapTypeChanged(_:)), for: .valueChanged)
Here is the method:
func mapTypeChanged(_ segControl: UISegmentedControl){
switch segControl.selectedSegmentIndex {
case 0:
mapView.mapType = .standard
case 1:
mapView.mapType = .hybrid
case 2:
mapView.mapType = .satellite
default:
break
}
}