Hey Everyone,
I’m trying to work through the end of chapter 6 and keep getting type MapViewController has no member “mapTypeChanged” as an error. I’ve checked and re-checked the code and I can’t figure what I’m doing wrong. Below is my code so far:
import UIKit
import MapKit
class MapViewController: UIViewController {
var mapView: MKMapView!
override func loadView() {
mapView = MKMapView()
view = mapView
let segmentedControl = UISegmentedControl(items: ["Standard","Hybrid","Satellite"])
segmentedControl.backgroundColor = UIColor.white.withAlphaComponent(0.5)
segmentedControl.selectedSegmentIndex = 0
segmentedControl.addTarget(self, action: #selector(MapViewController.mapTypeChanged(_:)), for: .valueChanged)
func mapTypeChanged(_ segControl: UISegmentedControl) {
switch segControl.selectedSegmentIndex {
case 0: mapView.mapType = .standard
case 1: mapView.mapType = .hybrid
case 2: mapView.mapType = .satellite
default: break
}
}
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(segmentedControl)
let topConstraint = segmentedControl.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 8)
let margins = view.layoutMarginsGuide
let leadingConstraint = segmentedControl.leadingAnchor.constraint(equalTo: margins.leadingAnchor)
let trailingConstraint = segmentedControl.trailingAnchor.constraint(equalTo: margins.trailingAnchor)
topConstraint.isActive = true
leadingConstraint.isActive = true
trailingConstraint.isActive = true
}
override func viewDidLoad() {
super.viewDidLoad()
print("MapViewController loaded its view.")
}
}