在主线程Swift上调用UI时不更新

时间:2016-08-16 18:59:42

标签: ios swift multithreading

我很难让我的注释的副标题更新,我在主线程上调用它并确保结果是正确的。

任何人都可以看到为什么它不会更新?

 let stopAnnotation: UUStopAnnotation = view.annotation as! UUStopAnnotation

        // Else get the stop estimation
        webService?.getStopEstimation(routeId: stopAnnotation.routeId, stopId: stopAnnotation.stopId, completion: { (result) in

            print(result)
            DispatchQueue.main.async(execute: {
                stopAnnotation.subtitle = result
            })

        })

3 个答案:

答案 0 :(得分:1)

您无法在地图中更改注释。删除此注释并将其替换为具有相同坐标但新副标题的注释。

答案 1 :(得分:0)

您是否尝试过强制地图视图重绘?

view.setNeedsDisplay()

答案 2 :(得分:0)

我通过添加以下内容修复了它:

    webService?.getStopEstimation(routeId: stopAnnotation.routeId, stopId: stopAnnotation.stopId, completion: { (result) in

        print(result)
        DispatchQueue.main.async(execute: {
            mapView.removeAnnotation(view.annotation!)
            stopAnnotation.subtitle = result
            mapView.addAnnotation(stopAnnotation)
            mapView.selectAnnotation(stopAnnotation, animated: true)
        })

    })
相关问题