gpt4 book ai didi

swift - Eureka : cannot convert value of type 'BaseRow?' to specified type 'CustomPushRow?'

转载 作者:行者123 更新时间:2023-11-28 06:22:51 26 4
gpt4 key购买 nike

我已将 Eureka 用于我的表单,但我遇到了问题。我使用这些代码设置表单

form +++ Section("Add Event")
<<< TextRow("Event"){ row in
row.title = "Event"
row.placeholder = "Enter Event Name Here"
}
<<< DateRow("Date"){
$0.title = "Date"
$0.value = selectedDate

}
<<< TimeRow("Time"){
$0.title = "Time"
$0.value = selectedDate

}
let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "eventLocation") as! EventLocationViewController

form +++ Section("Location")
<<< CustomPushRow<EventLocationViewController>(){
$0.title = "Location"
$0.presentationMode = .segueName(segueName: "eventLocation" ,controllerProvider: locationSearchTable, onDismiss: nil)

}

这里是自定义推送行类

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 的值

最佳答案

尝试以不同的方式获取您的信息(我从 Swift: How to get form values using Eureka form builder? 得到的提示帮助我解决了另一个“无法转换...的值”问题)

要读取给您错误消息的行上的值:

  1. 一定要在所有元素上设置标签 ($0.tag = "whatever")

  2. 代替

    让行:CustomPushRow? = form.rowBy(tag: "位置")

使用

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 类公开的 setValues(values: [String: Any?])。

例如:

form.setValues(["IntRowTag": 8, "TextRowTag": "Hello world!", "PushRowTag": Company(name:"Xmartlabs")])

其中"IntRowTag"、"TextRowTag"、"PushRowTag"为行标签(每一个唯一标识一行),8、"Hello world!"、Company(name:"Xmartlabs")为对应的行值赋值.

关于swift - Eureka : cannot convert value of type 'BaseRow?' to specified type 'CustomPushRow?' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42825272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com