2016-08-16 18 views
3

注釈のサブタイトルを更新するのに苦労しています。メインスレッドで呼び出して、結果が正しいことを確認しています。メインスレッドで呼び出されたときにUIが更新されないSwift

なぜ更新しないのか分かりますか?

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

     }) 

答えて

0

マップビューを強制的に再描画しようとしましたか?

view.setNeedsDisplay() 
1

マップ内の注釈を変更することはできません。この注釈を削除して、新しい字幕と同じ座標を持つ注釈で置き換えます。

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

    }) 
関連する問題