ios - Type 'MapViewController' has no member 'mapTypeChanged' Swift Big Nerd Ranch Guide -
[type 'mapviewcontroller' has no member 'maptypechanged'][2] in line:
action: #selector(mapviewcontroller.maptypechanged(_:)),
there method maptypechanged
@ bottom of code, i'm unsure why error says there no member maptypechanged
? i'm guessing maptypechanged needs declared variable (global?)
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) 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 func maptypechanged(_segcontrol: uisegmentedcontrol) { switch _segcontrol.selectedsegmentindex { case 0: mapview.maptype = .standard case 1: mapview.maptype = .hybrid case 2: mapview.maptype = .satellite default: break } } } override func viewdidload() { super.viewdidload() print("mapviewcontroller loaded view.") } }
#selector(mapviewcontroller.maptypechanged(_:))
means "call maptypechanged
method".
so need implement maptypechanged
.
func maptypechanged(_ sender: uisegmentedcontrol) { print(sender.selectedsegmentindex) }
Comments
Post a Comment