ios - Mapbox iOS SDK 3 - 点击注释时不显示注释标题

标签 ios xcode swift annotations mapbox

我很难弄清楚如何在用户点击指向当前位置的注释时显示注释标题。除此以外一切正常。我正在使用来自 https://github.com/varshylmobile/LocationManagerCLLocationManager 包装器但我认为它不会影响 Mapbox,因为我可以在 map 上正确显示我的图钉。

这是截图示例:

Mapbox with 2 annotations

如您所见,我可以毫无问题地运行该应用程序。只是当我为图钉设置一些注释标题和副标题,并在运行时点击它时,它没有显示任何内容。

这是我的注释代码片段:

        let point = MGLPointAnnotation()
        point.coordinate = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
        point.title = "Hello world!"
        point.subtitle = "Welcome to The Ellipse."

        self.mapView.addAnnotation(point)

        let point2 = MGLPointAnnotation()
        point2.coordinate = CLLocationCoordinate2D(latitude: 37.43259552, longitude: location.coordinate.longitude)
        point2.title = "Hello world!"
        point2.subtitle = "Welcome to The Ellipse."

        self.mapView.addAnnotation(point2)

        self.mapView.selectAnnotation(point, animated: true)
        self.mapView.showAnnotations([point, point2], animated: true)

这里是调用函​​数:

func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
    return true
}

func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? {
    return nil
}

我在 iOS 9.2、xCode 7 上。

谢谢!

最佳答案

实例化 map View 后我忘记了这行代码。

 mapView.delegate = self

谢谢!

关于ios - Mapbox iOS SDK 3 - 点击注释时不显示注释标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34829369/

相关文章:

ios - Xcode 9 本地化不起作用?

ios - SwiftUI 双向绑定(bind)到枚举案例中 ObservableObject 中的值

ios - 应用审查小组的 EXC_BREAKPOINT (SIGTRAP)。不可复制

ios - 仅当 indexPath 对象可用时如何在 tableview 单元格上使用标签

iphone - XIB 从 pushViewController 加载黑屏

iOS - 尝试读取 bundle.man.url 时不返回任何内容

ios - 如何以编程方式创建 Controller 和 UIView 而不是使用界面生成器?

objective-c - Xcode iOS : Retrieving values from NSDictionary and displaying it in UITextView

ios - Facebook iOS SDK : refreshing an expired access token without presenting a dialog

swift - UITest 失败并出现错误 'ld: entry point (_main) undefined. for architecture x86_64'