【问题标题】:MapView sorted by title annotations are changed when adding to map annotations array添加到地图注释数组时,按标题注释排序的 MapView 发生更改
【发布时间】:2021-06-30 11:50:18
【问题描述】:

我有一个显示在选择器视图上的分支对象数组,并且我根据这些分支数组详细信息创建了注释。我根据标题对分支数组和地图视图注释进行了排序,并将它们显示在地图视图上。每次我从选择器视图中选择一个分支时,地图都会放大到正确的分支注释并显示标注。

我的主要问题是分支根据标题正确排序,但地图注释从未正确排序。将sortedAnnotation 添加到mapView.addAnnotations 会更改排序。

let sortedAnnotations = mapView.annotations.sorted { rhs, lhs in
    if let rhsAnn = rhs.title, let rhsTitle = rhsAnn, let lhsAnn = lhs.title, let lhsTitle = lhsAnn {
        return rhsTitle < lhsTitle
    } else {
        return false
    }
}

mapView.addAnnotations(sortedAnnotations)

mapView.showAnnotations(mapView.annotations, animated: true)

【问题讨论】:

    标签: swift sorting dictionary annotations mkmapview


    【解决方案1】:

    addAnnotations 的数据源进行排序没有区别,因为注释的位置取决于坐标而不是标题

    【讨论】:

    • 感谢您的回答。这意味着我也必须根据坐标对分支数组进行排序?但是如何根据 lat 和 long 对数组进行排序。
    猜你喜欢
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多