Problem with the code on Page No 105 (Programmatic Controls)


#23

I struggled with this one too( working out of the 6th ed iOS Prog…). Just a little more clarification from a novice prospective:

segmentedControl.addTarget(self, action: #selector(MapViewController.mapTypeChanged(_:)), for: .valueChanged) code goes inside loadView.

While func mapTypeChanged(_ segControl: UISegmentedControl) is placed outside of loadView but inside class MapViewController.
See example below.

class MapViewController: UIViewController {

override func loadView( ) { ..........

segmentedControl.addTarget(self, action: #selector(MapViewController.mapTypeChanged(_:)), for: .valueChanged)
… }

func mapTypeChanged(_ segControl: UISegmentedControl){ ......

… }
}

I’m using Xcode 8.3.3.