【发布时间】:2018-06-19 05:08:44
【问题描述】:
我使用反向地理编码从纬度和经度获得地址并设置在标签中。但文本没有得到多行。因为在运行时单元格高度没有增加,我使用表格视图单元格自定义类并在单元格自定义类中的表格视图中设置数据,我使用下面的函数来获取地址并发送参数 pdblLatitude 和 pdblLongitude cellForRowAt 函数内
func getAdressName(pdblLatitude: String, withLongitude pdblLongitude: String)
{
var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
let lat: Double = Double("\(pdblLatitude)")!
//21.228124
let lon: Double = Double("\(pdblLongitude)")!
//72.833770
let ceo: CLGeocoder = CLGeocoder()
center.latitude = lat
center.longitude = lon
let loc: CLLocation = CLLocation(latitude:center.latitude, longitude: center.longitude)
ceo.reverseGeocodeLocation(loc) { (placemarks, error) in
if error != nil {
print("Hay un error")
} else {
var addressString : String = ""
let pm = placemarks! as [CLPlacemark]
if pm.count > 0 {
let pm = placemarks![0]
if pm.subLocality != nil {
addressString = addressString + pm.subLocality! + " "
}
if pm.locality != nil {
addressString = addressString + pm.locality! + " "
}
if pm.country != nil {
addressString = addressString + pm.country! + " "
}
print("addressString\(addressString)")
self.lbladdress.text = addressString
self.lbladdress.numberOfLines = 0
self.lbladdress.lineBreakMode = .byWordWrapping
LoadingView.shared.dismiss()
}
}
}
}
【问题讨论】:
-
您是否为标签使用了表格视图单元格的约束?如果是,那么约束存在一些问题,请先检查它们。
-
第二件事你需要在标签中设置文本后重新加载特定单元格,因为该方法是异步调用,它会在表格加载后调用并设置标签中的文本
-
@iOSDev,我已经在cell类里面的一个cell里面设置了数据
-
尝试在主线程中设置 self.lbladdress.text = addressString 和 self.lbladdress.superview.layoutifneed()
标签: ios uitableview swift4 xcode9.4