2016-11-30 15 views
1

こんにちはみんな。割り当て注釈への画像の代わりに、ピンIは、カスタムイメージに私の注釈にピンを交換しようとしています

イメージカセットリストには1X 2X 3Xなどが表示されますが、イメージを呼び出そうとすぐにXcodeが私の構文を修正しようとしますが、最終的にはそれをスローしますそれが尋ねる場所:エラー

私のコードは、オーバーライドFUNC

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

    guard !(annotation is MKUserLocation) else { 
     return nil 
    } 


    let annotationIdentifier = "AnnotationIdentifier" 

    var annotationView: MKAnnotationView? 
    if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) { 
     annotationView = dequeuedAnnotationView 
     annotationView?.annotation = annotation 
    } 
    else { 
     annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) 
     annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) 
    } 

    if let annotationView = annotationView { 

     annotationView.canShowCallout = true 
     annotationView.image = UIImage(named: "House") 
    } 

    return annotationView 
} 

Xcodeがコードにここでエラーを拾っているannotationView.image = UIImage(「家」という名前)の下に記載されているとしてアウト「挿入」、最終結果は、「家」

+0

エラーが何を言ってんセンタリングされていない問題がありますか? – GeneCode

+0

未解決の識別子「ハウス」の使用 – sabrefm1

答えて

0

スウィフト3イメージリテラルを導入し、未解決の識別子のエラー使用が表示されます。この

annotationView.image = UIImage(named: "#imageLiteral(resourceName: ",House,")") 

Xcodeのように見えます。 "Imag"と書くだけでImage Literalオプションでポップアップが開きます。画像の下のように:「イメージリテラル」オプションを選択することで

enter image description here

、それは、あなたがグリッドから使​​用したい

enter image description here

選択した画像を、利用可能なすべての資産の画像をポップアップします。詳細は

see this

0

このコードは私が

let pinImage = UIImage(named: "House.png") 
annotationView.image = pinImage 

私の問題を修正助けたが、私は今私のマップはもはや

関連する問題