2017-05-21 10 views
-1

テーブルビューのセルにUILabelがあります。これは、2つの座標間の距離を常に表示する必要があります。私は2つの座標(緯度と経度)を持っています。今度は、2つの座標の間の距離を表示するのに成功しましたが、テーブルビューを常に更新することなく、人が動くにつれて私はいつもUILabelを更新できますか?ここでMiles awayテーブルビューセル

は私のコードです:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cells", for: indexPath as IndexPath) as! MyCell 
    cell.object = object 
    let currentLocation = CLLocation() 
    locManager.distanceFilter = 50 
    if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse || 
     CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){ 
     let coordinate₀ = CLLocation(latitude: CLLocationDegrees(-41)!, longitude: CLLocationDegrees(52.3)!) 
     let coordinate₁ = CLLocation(latitude: currentLocation.coordinate.longitude, longitude: currentLocation.coordinate.latitude) 
     let distanceInMeters = coordinate₀.distance(from: coordinate₁) 
     if(distanceInMeters <= 1609) 
     { 
      cell.Distance.text = "\(Float(round(distanceInMeters * 3.28084)).cleanValue) ft" 
     } 
     else 
     { 
      cell.Distance.text = "\(Float(round(distanceInMeters/1609)).cleanValue) mi" 
     } 
    } 
} 

答えて

0

あなたが全体UITableViewをリロードしたくない場合は、おそらくあなたはそれの特定の行をリロードすることができますか?

func reloadRows(at: [IndexPath], with: UITableViewRowAnimation)

あなたはどちらかそれこれを実行したくない場合は、多分あなたは完全UITableViewのうち、この見解を取って検討すべきです。

+0

現在の位置を変更してビューを再読み込みすると、距離は変わりません。どうすればいいですか – john

+0

間違っている可能性のあることがいくつかあります。計算コードにブレークポイントを設定します。関数が呼び出され、新しい計算が実際に正しいことを確認します。 –

関連する問題