2016-12-05 9 views
-1

私はの3種類のマップビュー "Standard"、 ".Hybrid"、 "Satellite"を切り替えることを目指しています。 ".addTarget"行に次のエラーが表示されます。UISegmentedControl Swiftのターゲットの割り当て3

"ソースファイル内のエディタのプレースホルダ"

let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"]) 
    segmentedControl.backgroundColor = UIColor.white.withAlphaComponent(0.5) 
    segmentedControl.selectedSegmentIndex = 0 

    // EVENT LISTENER FOR SEGMENT CONTROL 
    segmentedControl.addTarget(self, action: "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 
     } 

    } 

答えて

1
let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"]) 
segmentedControl.backgroundColor = UIColor.white.withAlphaComponent(0.5) 
segmentedControl.selectedSegmentIndex = 0 

// EVENT LISTENER FOR SEGMENT CONTROL 
segmentedControl.addTarget(self, action: "mapTypeChanged:", for: .valueChanged) 

func mapTypeChanged() //removing the auto complete params 
{ 
    switch segControl.selectedSegmentIndex{ 
    case 0: 
     mapView.mapType = .standard 
    case 1: 
     mapView.mapType = .hybrid 
    case 2: 
     mapView.mapType = .satellite 
    default: 
     break 
    } 

} 

のplsはこれを試してください。..

0

ここで起こって物事のカップル。 #selectorを使用して、関数の宣言を変更して最初の引数の命名を抑制する必要があります。そうでないと、セレクタでも宣言する必要があります。

let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"]) 
    segmentedControl.backgroundColor = UIColor.white.withAlphaComponent(0.5) 
    segmentedControl.selectedSegmentIndex = 0 

// EVENT LISTENER FOR SEGMENT CONTROL 

segmentedControl.addTarget(nil, action: #selector(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 
    } 
} 
+0

私は新しいエラーメッセージが出ます: – dave

+0

「ローカル変数の使用 『をmapTypeChanged』は、その宣言の前に、」あなたはこのコードを挿入している – dave

+0

? ViewControllerの中に? –

関連する問題