0
내 응용 프로그램에는 다른 이미지가있는 점을 보여주는지도가 있습니다. 이미지를 정의하는 데 사용되는 일부 매개 변수를 변경하면 표식을 제거하고 추가하여 맵을 업데이트하려고합니다. 문제는 주석을 업데이트하고 다시 추가 할 때 viewFor annotation 메서드는 주석을 nil로받습니다. 나는 무엇을 잘못 할 수 있습니까? 여기Viewforannotation은 내지도를 업데이트 한 후 주석을 nil로 가져옵니다.
내가 변경 한 후 내지도를 업데이트하고하는 것은 : 당신이 고려할 수있는 어떤
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationIdentifier = "pin"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView?.canShowCallout = true
var categoryName = ""
var colorName = ""
// Resize image
if annotation is MyAnnotation{
let index = (annotation as! MyAnnotation).annotationIndex
let annotationData = searchResult[index]
let categories = annotationData.object(forKey: "category") as! NSArray
for item in categories {
let category = item as! String
if hasCategory(category: category) {
categoryName = translateCategoryName(category: category)
break
}
}
let status = annotationData.object(forKey: "status") as! String
if status == "Lotado"{
colorName = "vermelho"
} else if status == "Quase cheio"{
colorName = "laranja"
} else if status == "Médio"{
colorName = "amarelo"
}else if status == "Vazio"{
colorName = "verde"
} else {
colorName = "cinza"
}
}
var imageName = ""
if categoryName != "" {
imageName = "\(colorName)-\(categoryName)"
} else {
imageName = "verde-padaria"
}
if annotation is MKUserLocation {
let userAvatar = defaults.integer(forKey: "avatarNumber")
imageName = "balao-avatar\(userAvatar)"
}
let pinImage = UIImage(named: imageName)
let size = CGSize(width: 30, height: 50)
UIGraphicsBeginImageContext(size)
pinImage?.draw(in: CGRect.init(x: 0.0, y: 0.0, width: size.width, height: size.height))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
annotationView?.image = resizedImage
if !(annotation is MKUserLocation) {
let btn = UIButton(type: .infoLight)
btn.addTarget(self,action:#selector(showEstablishment),for:.touchUpInside)
annotationView?.rightCalloutAccessoryView = btn
}
return annotationView
}
else {
annotationView?.annotation = annotation
}
return annotationView
}
http://stackoverflow.com/questions/25591038/is-there-any-m 큐에서 큐로 사용되는 큐로 재사용 가능한 주석으로보기 – breno