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内のさまざまなセルを更新するにはどうすればよいですか?
で
tableView.reloadData()
を行うことです。ありがとう – sesc360