2017-05-21 58 views
-1

我有一個UILabel在一個表格視圖單元格,我需要不斷顯示兩個座標之間的英里之間。我有兩個座標(經度和緯度)。現在它成功顯示了兩個座標之間的距離,但是如何隨着人的移動而不斷更新UILabel而無需不斷刷新桌面視圖?萬里之外桌面單元格

這裏是我的代碼:

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

可能有幾件事情可能會出錯。在計算代碼中放置一個斷點。驗證函數是否被調用,並且新的計算確實是正確的。 –