【发布时间】:2017-02-17 21:21:47
【问题描述】:
对于 iOS 开发人员来说相当新,我正在学习 Swift (https://www.mapbox.com/help/first-steps-ios-sdk/) 的“iOS MapBox SDK 的第一步”教程。 显示地图、自定义样式和添加注释都很好。但是在尝试与注释交互以显示其标题和副标题时遇到了问题。
print("allow") print("tap on callout") 似乎从未被调用过。甚至mapView.selectAnnotation(point, animated: true) 也没有做任何事情(没有它也没有做任何事情)
使用 xCode 8.0、MacOS Sierra、Swift 3、iOS 10
我现在有点不知所措,任何建议都将不胜感激
提前致谢
ViewController.swift:
import UIKit
import Mapbox
class ViewController: UIViewController{
@IBOutlet var mapView: MGLMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: 46.082666, longitude:7.508510)
point.title = "Title"
point.subtitle = "Subtitle"
mapView.addAnnotation(point)
mapView.selectAnnotation(point, animated: true)
print("add annotation");
}
// Return `nil` here to use the default marker.
func mapView(mapView: MGLMapView, viewForAnnotation annotation: MGLPointAnnotation) -> MGLAnnotationView? {
print("default marker")
return nil
}
// Allow callout view to appear when an annotation is tapped.
func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLPointAnnotation) -> Bool {
print("allow")
return true
}
func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) {
print("tap on callout")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Screenshot: Annotation displays where it's supposed to but cannot be interacted with
【问题讨论】:
-
mapView 代理设置了吗?
-
您的标签已经表明您正在使用 Swift。无需将其添加到标题中。