2017-03-16 63 views
1

我已经使用Eureka作为我的表单,但我正面临一个问题。我安装使用这些代码尤里卡:无法转换'BaseRow'类型的值?指定类型'CustomPushRow?'

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

回答

0

值尝试把你的信息以不同的方式(一个提示,我从Swift: How to get form values using Eureka form builder?得到了帮助我的另一个“不能转换值... ”问题)

要在一排,让你的错误信息读出的值:

  1. 一定要在所有的元素($ 0.tag =设置标签‘无所谓’)

  2. 代替

    令行:CustomPushRow? = form.rowBy(标签: “位置”)

使用

let dict = self.form.values(includeHidden: true) 

然后,你可以看到价值的东西,如

print(dict["whatever"]) 

现在,你的问题的另一部分问有关设置价值,这在尤里卡是另一回事。

从文档(https://github.com/xmartlabs/Eureka#how-to-set-the-form-values-using-a-dictionary):

如何使用字典

调用setValues方法来设置的形式的值(值:[字符串:任何?]),其通过Form类暴露。

例如:

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

其中 “IntRowTag”, “TextRowTag”, “PushRowTag” 是行标签(每一个唯一标识行)和8日, “世界,你好!”,公司(名称: “Xmartlabs”)是要分配的相应行值。

相关问题