2016-03-25 19 views
0

位置更新が受信されたときにTableViewを更新したいので、ユーザーに表示する距離ラベルを更新します。私は更新を通知する通知を作成しました。位置更新を受信したときにTableViewセルを更新する

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細胞は、データソース内に充填されている:

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 
    } 

Iであれば、現在位置が受信されないようcalculateDistance

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

方法を介して距離を計算する。しかし、私のテーブルビューに間違った値があります。

通知を受け取るとすぐにtableView内のさまざまなセルを更新するにはどうすればよいですか?

答えて

1

最も簡単な方法は、今、私はそれを読むことを理にかなってそれだけでlocationAvailable

+0

tableView.reloadData()を行うことです。ありがとう – sesc360

関連する問題