【发布时间】:2020-06-27 05:33:31
【问题描述】:
注解在地图上显示时,可以构建并执行,但执行过程中出错并停止。 MKMarkerAnnotationView 显示聚类和字形图像。 大约有 100 个注解,在加载 View 时从 Firestore 获取并存储在一个数组中。 地图放大或移动时发生错误。 斯威夫特版本:斯威夫特5 我也检查了插座连接,但看起来没有问题。
找不到解决方案,您能告诉我出了什么问题吗? 我写了Map等的设置方法,但如果根本错误,请教我。
错误 [XXX.CustomPinAnnotation memberAnnotations]:无法识别的选择器发送到实例 0x2835e16c0
- 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[XXX.CustomPinAnnotation memberAnnotations]:无法识别的选择器发送到实例 0x2835e16c0”* 第一次抛出调用堆栈:
CustomPinAnnotation.swift
import UIKit
import MapKit
class CustomPinAnnotation: NSObject, MKAnnotation {
let clusteringIdentifier : String
let title: String?
let subtitle: String?
let coordinate: CLLocationCoordinate2D
//let glyphText: String
let glyphImage: UIImage
let glyphTintColor: UIColor
let markerTintColor: UIColor
let objectid: Int
init(_ clusteringIdentifier: String, title: String, subtitle: String, coordinate: CLLocationCoordinate2D, glyphImage: UIImage, glyphTintColor: UIColor, markerTintColor: UIColor, objectid: Int) {
self.clusteringIdentifier = clusteringIdentifier
self.title = title
self.subtitle = subtitle
self.coordinate = coordinate
// self.glyphText = glyphText
self.glyphImage = glyphImage
self.glyphTintColor = glyphTintColor
self.markerTintColor = markerTintColor
self.objectid = objectid
}
}
ViewController.swift
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
var locationManager = CLLocationManager()
var userCoordinate = CLLocationCoordinate2D()
//object array
var objectAll = [objectData]()
//Map view
@IBOutlet weak var mapView: MKMapView!
func displayAllMountains() {
for mountain in objectAll {
let pinImage = UIImage.init(named: "XXXXX")!
let subtitletext = String(object.height) + "m"
let annotation = CustomPinAnnotation("clusterid", title:object.name, subtitle: subtitletext, coordinate: object.geopoint, glyphImage: pinImage, glyphTintColor: .white, markerTintColor: .darkGray, objectid: object.objectid)
self.mapView.addAnnotation(annotation)
}
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation === mapView.userLocation {
return nil
} else {
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier, for: annotation)
guard let markerAnnotationView = annotationView as? MKMarkerAnnotationView,
let annotation = annotation as? CustomPinAnnotation else {
return annotationView
}
markerAnnotationView.clusteringIdentifier = annotation.clusteringIdentifier
// markerAnnotationView.glyphText = annotation.glyphText
markerAnnotationView.glyphImage = annotation.glyphImage
markerAnnotationView.glyphTintColor = annotation.glyphTintColor
markerAnnotationView.markerTintColor = annotation.markerTintColor
return markerAnnotationView
}
}
}
【问题讨论】:
标签: ios swift mkannotation