現在の住所をTableViewCell
に表示したいと思います。私は緯度と経度を持っていますが、セルにアドレス文字列を表示する方法を理解できません。iOSのtableViewCellの現在の位置を表示するには
ViewDidLoad()
に次のコードを書きました。ラベルにアドレスが表示されています。
let manager: CLLocationManager = locationManager
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)->Void in
let placemark = placemarks?[0]
let lines = placemark?.addressDictionary?["FormattedAddressLines"]
let addressString = (lines as! NSArray).componentsJoined(by: "\n")
self.lblAddress.text = addressString
print(addressString)
})
but i want to show the address on tableview Cell.
//return cell for perticular row withing section
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if indexPath.section <= 1
{
let cell = tableView.dequeueReusableCell(withIdentifier: "CellRID", for: indexPath)
cell.textLabel?.text = "\(self.batteryLevel() * 100) %"
return cell
}
else
{
//create reusable cell object by dequeueReusableCellWithIdentifier
//identifier must register with cell
let cell = tableView.dequeueReusableCell(withIdentifier: "LocationTableViewCellRID", for: indexPath) as! LocationTableViewCell
let personName = txtFieldName.text
let a = LocationVC()
cell.lblName?.text = "\(personName) \(self.batteryLevel() * 100) %"
cell.lblAddress?.text =
return cell
}
}
lblAddressにアドレスを表示したいとします。私はiOSを初めて使っています。アドバイスをいただきありがとうございます。
あなたはLAT-LONから位置アドレスを取得できます?もしあれば、アドレス&を保持する文字列(例えばaddressString)オブジェクトを作成します。cellforRowAtIndexPath cell.lblAddress?.text = addressString –
私はすでにそれを試みましたが、 "未解決の識別子 'addressString'の使用" – Innate
を宣言しています。 ViewDidLoadの –