我想顯示當前位置地址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
你在哪裏聲明你的字符串? –