Ios 在主线程上调用时未更新UI
我很难更新注释的副标题,我在主线程上调用它并确保结果是正确的 有人知道为什么不更新吗Ios 在主线程上调用时未更新UI,ios,swift,multithreading,Ios,Swift,Multithreading,我很难更新注释的副标题,我在主线程上调用它并确保结果是正确的 有人知道为什么不更新吗 let stopAnnotation: UUStopAnnotation = view.annotation as! UUStopAnnotation // Else get the stop estimation webService?.getStopEstimation(routeId: stopAnnotation.routeId, stopId: stopAnnota
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
})
})
您是否尝试过强制地图视图重新绘制自身
view.setNeedsDisplay()
无法更改地图中的注释。删除此注释并将其替换为具有相同坐标但具有新字幕的注释。我通过添加以下内容修复了此注释:
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)
})
})