Swift主线程调用UI未更新

4

我在更新我的注释副标题时遇到了困难,我正在主线程上调用它并确保结果是正确的。

有人能看出为什么它没有更新吗?

 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个回答

1
您无法更改地图上的注释。请删除此注释,并用具有相同坐标但新副标题的注释替换它。

1
我通过添加以下内容解决了它:


    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)
        })

    })

0
你尝试过强制地图视图重新绘制吗?
view.setNeedsDisplay()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接