我有一个表单,用户可以从中选择许多包含坐标数据的对象,我希望将这些数据加载到LocationRow中。
我尝试了几种不同的方法来尝试设置“位置行”值,但是它要么崩溃(在展开一个可选值时意外发现nil),要么没有用正确的数据重新加载该表。即https://i.imgur.com/2XkeHbu.png
我的LocationRow eureka代码:
$0.rowRight = LocationRow(){
$0.title = "Location"
$0.tag = "location"
if let page = selectedPage {
if let pageLocationLatitude = page.locationLatitude.value,
let pageLocationLongutude = page.locationLongitude.value {
print("testing for row update")
$0.value = CLLocation(latitude: pageLocationLatitude, longitude: pageLocationLongutude)
}
}
}
以及我要更新LocationRow时调用的函数
private func setSelectedPage(pageName : String) {
print("setting location of page: \(pageName)")
if pageName == username {
return
}
selectedPage = userPages?.filter("name == \"\(pageName)\"").first
if let locationLongitude = selectedPage?.locationLongitude.value,
let locationLatitude = selectedPage?.locationLatitude.value {
print("lat and lon: \(locationLatitude) \(locationLongitude)")
/*PURELY FOR TESTING
let titleRow = self.form.rowBy(tag: "title") as! TextRow
titleRow.value = "TEST WORKS OK"
titleRow.updateCell()
PURELY FOR TESTING */
let locationRow = self.form.rowBy(tag: "location") as! LocationRow
locationRow.value = CLLocation(latitude: locationLatitude, longitude: locationLongitude)
self.form.rowBy(tag: "location")?.updateCell()
}
self.tableView.reloadData()
}
从您的代码中,我可以看到您正在将此位置行放入SplitRow
:
// rowRight is a property of SplitRow
$0.rowRight = LocationRow(){
因此,表单并不真正知道位置行。它只知道拆分行。您应该首先使用its标记获取拆分行,然后访问rowRight
。
// use the tag of your split row here!
let splitRow = self.form.rowBy(tag: "splitRow")
as! SplitRow<SomeRow, LocationRow> // replace SomeRow with the type of row on the left of the split row
let locationRow = splitRow.rowRight
locationRow.value = CLLocation(latitude: locationLatitude, longitude: locationLongitude)
locationRow.updateCell()