Eureka:无法将类型 'BaseRow?' 的值转换为指定类型 'CustomPushRow?'
Eureka : cannot convert value of type 'BaseRow?' to specified type 'CustomPushRow?'
我在表单中使用了 Eureka,但我遇到了问题。我使用这些代码设置表单
form +++ Section("Add Event")
<<< TextRow("Event"){ row in
row.title = "Event"
row.placeholder = "Enter Event Name Here"
}
<<< DateRow("Date"){
[=12=].title = "Date"
[=12=].value = selectedDate
}
<<< TimeRow("Time"){
[=12=].title = "Time"
[=12=].value = selectedDate
}
let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "eventLocation") as! EventLocationViewController
form +++ Section("Location")
<<< CustomPushRow<EventLocationViewController>(){
[=12=].title = "Location"
[=12=].presentationMode = .segueName(segueName: "eventLocation" ,controllerProvider: locationSearchTable, onDismiss: nil)
}
这里是自定义推送行class
public final class CustomPushRow<T: Equatable>: SelectorRow<PushSelectorCell<T>, SelectorViewController<T>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
presentationMode = .show(controllerProvider: ControllerProvider.callback {
return SelectorViewController<T>(){ _ in }
}, onDismiss: { vc in
print("On Dimiss")
_ = vc.navigationController?.popViewController(animated: true)
})
}
}
当我想更改表单的值时,我使用此方法更改
let eventName : TextRow? = form.rowBy(tag:"Event")
eventName?.value = "asdasadsds"
但是当我想更改自定义推送行时我遇到了这个问题无法将类型 'BaseRow?' 的值转换为指定类型 'CustomPushRow?' 当我这样做时
let row : CustomPushRow? = form.rowBy(tag: "Location")
如何更改 CustomPushRow 的值
尝试以不同的方式获取您的信息(我从 得到的提示帮助我解决了另一个 "cannot convert value of...." 问题)
读取出现错误消息的行中的值:
一定要在所有元素上设置标签 ($0.tag = "whatever")
而不是
让行:CustomPushRow? = form.rowBy(标签:"Location")
使用
let dict = self.form.values(includeHidden: true)
然后你可以看到类似
的值
print(dict["whatever"])
现在,你问题的另一部分询问了关于设置值的问题,这在 Eureka 中是不同的。
来自文档 (https://github.com/xmartlabs/Eureka#how-to-set-the-form-values-using-a-dictionary):
How to set the form values using a dictionary
调用由 Form class.
公开的 setValues(values: [String: Any?])
例如:
form.setValues(["IntRowTag": 8, "TextRowTag": "Hello world!", "PushRowTag": Company(name:"Xmartlabs")])
其中"IntRowTag"、"TextRowTag"、"PushRowTag"为行标签(每一个唯一标识一行)和8、"Hello world!"、Company(name:"Xmartlabs") 是要分配的相应行值。
我在表单中使用了 Eureka,但我遇到了问题。我使用这些代码设置表单
form +++ Section("Add Event")
<<< TextRow("Event"){ row in
row.title = "Event"
row.placeholder = "Enter Event Name Here"
}
<<< DateRow("Date"){
[=12=].title = "Date"
[=12=].value = selectedDate
}
<<< TimeRow("Time"){
[=12=].title = "Time"
[=12=].value = selectedDate
}
let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "eventLocation") as! EventLocationViewController
form +++ Section("Location")
<<< CustomPushRow<EventLocationViewController>(){
[=12=].title = "Location"
[=12=].presentationMode = .segueName(segueName: "eventLocation" ,controllerProvider: locationSearchTable, onDismiss: nil)
}
这里是自定义推送行class
public final class CustomPushRow<T: Equatable>: SelectorRow<PushSelectorCell<T>, SelectorViewController<T>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
presentationMode = .show(controllerProvider: ControllerProvider.callback {
return SelectorViewController<T>(){ _ in }
}, onDismiss: { vc in
print("On Dimiss")
_ = vc.navigationController?.popViewController(animated: true)
})
}
}
当我想更改表单的值时,我使用此方法更改
let eventName : TextRow? = form.rowBy(tag:"Event")
eventName?.value = "asdasadsds"
但是当我想更改自定义推送行时我遇到了这个问题无法将类型 'BaseRow?' 的值转换为指定类型 'CustomPushRow?' 当我这样做时
let row : CustomPushRow? = form.rowBy(tag: "Location")
如何更改 CustomPushRow 的值
尝试以不同的方式获取您的信息(我从
读取出现错误消息的行中的值:
一定要在所有元素上设置标签 ($0.tag = "whatever")
而不是
让行:CustomPushRow? = form.rowBy(标签:"Location")
使用
let dict = self.form.values(includeHidden: true)
然后你可以看到类似
的值print(dict["whatever"])
现在,你问题的另一部分询问了关于设置值的问题,这在 Eureka 中是不同的。
来自文档 (https://github.com/xmartlabs/Eureka#how-to-set-the-form-values-using-a-dictionary):
How to set the form values using a dictionary
调用由 Form class.
公开的 setValues(values: [String: Any?])例如:
form.setValues(["IntRowTag": 8, "TextRowTag": "Hello world!", "PushRowTag": Company(name:"Xmartlabs")])
其中"IntRowTag"、"TextRowTag"、"PushRowTag"为行标签(每一个唯一标识一行)和8、"Hello world!"、Company(name:"Xmartlabs") 是要分配的相应行值。