Eureka Swift - 设置 LocationRow 的值
Eureka Swift - set value of LocationRow
我有一个表单,用户可以在其中从包含坐标数据的多个对象中进行选择,我想将这些数据加载到 LocationRow 中。
我尝试了几种不同的方法来尝试设置 Location Row 值,但它要么崩溃(在展开可选值时意外发现 nil),要么没有用正确的数据重新加载 table。即 https://i.imgur.com/2XkeHbu.png
我的 LocationRow 尤里卡代码:
[=11=].rowRight = LocationRow(){
[=11=].title = "Location"
[=11=].tag = "location"
if let page = selectedPage {
if let pageLocationLatitude = page.locationLatitude.value,
let pageLocationLongutude = page.locationLongitude.value {
print("testing for row update")
[=11=].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
[=10=].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()
我有一个表单,用户可以在其中从包含坐标数据的多个对象中进行选择,我想将这些数据加载到 LocationRow 中。
我尝试了几种不同的方法来尝试设置 Location Row 值,但它要么崩溃(在展开可选值时意外发现 nil),要么没有用正确的数据重新加载 table。即 https://i.imgur.com/2XkeHbu.png
我的 LocationRow 尤里卡代码:
[=11=].rowRight = LocationRow(){
[=11=].title = "Location"
[=11=].tag = "location"
if let page = selectedPage {
if let pageLocationLatitude = page.locationLatitude.value,
let pageLocationLongutude = page.locationLongitude.value {
print("testing for row update")
[=11=].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
[=10=].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()