Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios mapkit中未解析的标识符_Ios_Swift_Swift3_Mapkit_Mkannotation - Fatal编程技术网

Ios mapkit中未解析的标识符

Ios mapkit中未解析的标识符,ios,swift,swift3,mapkit,mkannotation,Ios,Swift,Swift3,Mapkit,Mkannotation,下面的代码是关于堆栈溢出的相同问题。然而,看起来代码是在swift 2中。我为一些代码添加了一个图像jj,但是我收到了一条错误消息。错误消息是var-anView=thisMAP.dequeueReusableAnnotationView(带标识符:reuseId)。错误消息指出,reuseId是唯一错误消息的未解析标识符。如果这是固定的代码将编译 import UIKit import MapKit class Annotation: NSObject, MKAnnotation { var

下面的代码是关于堆栈溢出的相同问题。然而,看起来代码是在swift 2中。我为一些代码添加了一个图像jj,但是我收到了一条错误消息。错误消息是
var-anView=thisMAP.dequeueReusableAnnotationView(带标识符:reuseId)
。错误消息指出,reuseId是唯一错误消息的未解析标识符。如果这是固定的代码将编译

import UIKit
import MapKit

class Annotation: NSObject, MKAnnotation
{
var coordinate: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
var custom_image: Bool = true
var color: MKPinAnnotationColor = MKPinAnnotationColor.purple
}
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var thisMAP: MKMapView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.thisMAP.delegate = self;

    let annotation = Annotation()
    thisMAP.addAnnotation(annotation)

    let annotation2 = Annotation()
    annotation2.coordinate = CLLocationCoordinate2D(latitude: 0.0, longitude: 1.0)
    annotation2.custom_image = false
    thisMAP.addAnnotation(annotation2)

    let annotation3 = Annotation()
    annotation3.coordinate = CLLocationCoordinate2D(latitude: 1.0, longitude:  0.0)
    annotation3.custom_image = false
    annotation3.color = MKPinAnnotationColor.green
    thisMAP.addAnnotation(annotation3)
}

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if (annotation is MKUserLocation) {
        return nil
    }

    var anView = thisMAP.dequeueReusableAnnotationView(withIdentifier: reuseId )

    if anView == nil {
        if let anAnnotation = annotation as? Annotation {
            if anAnnotation.custom_image {
                let reuseId = "jj.png"
                anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
                anView.image = UIImage(named:"jj.png")
            }
            else {
                let reuseId = "pin"
                let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
                pinView.pinColor = anAnnotation.color
                anView = pinView
            }
        }
        anView.canShowCallout = false
    }
    else {
        anView.annotation = annotation

在这一行中,reuseID在此位置是未知的-仅在
if else
块中,这就是为什么错误
reuseID是一个未解析的标识符的原因:

    var anView = thisMAP.dequeueReusableAnnotationView(withIdentifier: reuseId )
您只能在定义它的范围内使用它

reuseID
的定义放在此行之前


它应该与您在
if ananotation.custom_image{

中定义的
reuseId
相同,您将reuseId定义为什么?