无法从MapView获取自定义模型确实更改了状态功能

用户

拖动状态结束后,我正在尝试打印出我的帖子模型,但是由于某种原因,它不会打印出任何内容。我已附上我的模型,该模型可以正常viewFor运行。感谢您的任何提前帮助。

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, didChange newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState) {

    if newState == MKAnnotationViewDragState.ending {
        if let annon = view.annotation?.coordinate as? MyAnno {

            print(annon.post?.id) //Not working

            view.dragState = MKAnnotationViewDragState.none
        }
    }
}

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    var annotationView = MKMarkerAnnotationView()
    guard let annotation = annotation as? MyAnno else {return nil}
    var identifier = ""
    if let dequedView = mapView.dequeueReusableAnnotationView(
        withIdentifier: identifier)
        as? MKMarkerAnnotationView {
        annotationView = dequedView
    } else {
        annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
}

模型:

class MyAnno: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var post: Post?
var title: String?

init(post: Post, title: String?, subtitle: String?, latitude:CLLocationDegrees, longitude:CLLocationDegrees) {
    self.coordinate = CLLocationCoordinate2DMake(latitude, longitude)
    self.title = title
}
}
巴拉特·比斯瓦尔(Bharat Biswal)

我认为有一个.coordinate不需要的

请更改此行:

if let annon = view.annotation?.coordinate as? MyAnno {

if let annon = view.annotation as? MyAnno {

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

uwp获取自定义媒体控件中视觉状态更改的通知

在Woocommerce 3中更改电子邮件主题以获取自定义订单状态

获取自定义jQuery插件功能列表

在Wordpress中获取自定义字段的功能

无法从Firestore获取自定义对象

无法从支持Bean获取自定义组件属性

如何获取自定义数据

获取自定义属性值

获取自定义视图的项目

如何获取自定义UIPickerView

获取自定义woocommerce产品

从DataGridViewComboBoxColumn获取自定义类型

无法读取自定义属性

如何在SaveViewState覆盖方法中获取自定义控件的可见状态

http响应状态为400时,使用fetch api获取自定义错误消息

有没有办法从discord.py获取自定义状态消息?

如何将自定义图标放置到 Visio 文档以获取自定义功能区

如何获取自定义UITableViewCell以获取用户对首选文本大小的更改?

Django-如何使用get_object_or_404获取自定义用户模型

Laravel获取自定义模型属性不起作用

自定义元素原型中的重写功能更改了此对象

无法通过JavaScript更改创建的自定义状态原因

无法从其他应用获取自定义帐户的AuthToken

无法从“ index.js”解析模块以获取自定义组件

viewForAnnotation有时无法获取自定义MKAnnotation类并正确呈现它

无法通过Android Drive API获取自定义属性

无法获取自定义字体以加载到iOS应用中

无法使用JavaScript在客户端获取自定义标头

无法在 2checkout 响应中获取自定义参数