gpt4 book ai didi

ios - 类布局

转载 作者:行者123 更新时间:2023-11-28 08:20:23 26 4
gpt4 key购买 nike

我对两个代码块之间的链接有疑问,这有望改变注释图像。我是 swift 的新手,所以我很难在 mapView 上找到它。我在函数中给出了一个代码,用于在运行时打印一个字符串,但该字符串未显示在 NSLog 中。这是否意味着该功能根本没有运行?对于我哪里出错的任何建议,我将不胜感激。谢谢

class ViewController2: UIViewController {

@IBOutlet var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()

//Location for first Pin
let locationOne = CLLocationCoordinate2DMake(-47.016945, 167.852095)

//Location for map centering
let locationNZ = CLLocationCoordinate2DMake(-43.937462, 170.507813)
let span = MKCoordinateSpanMake(9, 9)
let region = MKCoordinateRegion(center: locationNZ, span: span)
mapView.setRegion(region, animated: true)

//Create annotation one
let annotation = MKPointAnnotation()
annotation.coordinate = locationOne
annotation.subtitle = "Park"
annotation.title = "Rakiura National Park"

//Add annotation to the map
mapView.addAnnotation(annotation)}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()}




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

print("func")
guard !annotation.isKind(of: MKUserLocation.self) else {
return nil}

let annotationIdentifier = "AnnotationIdentifier"

var annotationView: MKAnnotationView?
if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) {
annotationView = dequeuedAnnotationView
annotationView?.annotation = annotation}
else {

let av = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
av.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
annotationView = av}

if let annotationView = annotationView {
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "mapIcon.png")}

return annotationView}}

最佳答案

听起来您可能遇到了我忘记设置代理所以我的代理永远不会被调用的问题;当您的委托(delegate)方法未触发时,这应该始终是您所怀疑的。尝试

mapView.delegate = self

关于ios - 类布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41497844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com