2017-03-16 40 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」)是要分配的相應行值。

相關問題