2016-03-25 11 views
0

Bir yer güncellemesi alındığında TableView'imi güncellemek ve dolayısıyla kullanıcıya gösterdiğim bir uzaklık etiketini güncellemek istiyorum. Güncellemeyi bana bildirecek bir bildirim oluşturdum.Konum Güncellemesi alındığında TableView Hücresi güncelleniyor

self.notificationCenter.addObserver(self, selector: "locationAvailable:", name: "LOCATION_AVAILABLE", object: nil) 

func locationAvailable(notification: NSNotification) { 
    let userInfo = notification.userInfo as! Dictionary<String, AnyObject> 
    self.currentLocation = userInfo["location"] as! CLLocation 
} 

tableView hücreleri veri kaynağı doldurulur:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cellIdentifier = "Cell" 
     let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AEDTableViewCell 

     let aed: AED = self.aeds[indexPath.row] 

     // Configure the cell 
     cell.streetName.text = aed.street! 
     cell.owner.text = aed.owner! 
     cell.distanceLabel.text = String(format: "%.0f" + "m", calculateDistance(currentLocation: self.currentLocation, latitude: aed.latitude!, longitude: aed.longitude!)) 

     return cell 
    } 

bir yöntem calculateDistance

calculateDistance(currentLocation: self.currentLocation, latitude: aed.latitude!, longitude: aed.longitude!) 

Ancak ile mesafe hesaplamak sürece, mevcut yer almamış olduğu gibi, masaüstümde yanlış bir değer var.

Bildirimi aldığım anda tablodaki farklı hücreleri nasıl güncellerim?

cevap

1

kolay yolu sadece yapmaktır bir tableView.reloadData() şimdi okudum mantıklı

+0

locationAvailable içinde. Teşekkürler – sesc360