我想显示当前位置地址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
你在哪里声明你的字符串? –