我将旧项目迁移到Swift 4,因此自然地我也更新到了Eureka 4.3。
在旧项目中,有一个名为LatitudeSelectorRow
的自定义行,它显示一个LatitudeSelectorController
。
LatitudeSelectorRow
以前是这样的:
final class LatitudeSelectorRow: SelectorRow<PushSelectorCell<CLLocationDegrees>, LatitudeSelectorController> {
required init(tag: String?, _ initializer: ((LatitudeSelectorRow) -> ())) {
super.init(tag: tag)
initializer(self)
// Focus on here!!
presentationMode = PresentationMode.show(controllerProvider: ControllerProvider.storyBoard(storyboardId: "LatitudeSelector", storyboardName: "Main", bundle: nil), completionCallback: {
_ in
})
displayValueFor = {
...
}
}
required convenience init(tag: String?) {
self.init(tag: tag)
}
}
LatitudeSelectorController
过去看起来像这样:
class LatitudeSelectorController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, TypedRowControllerType {
/// A closure to be called when the controller disappears.
public var onDismissCallback: ((UIViewController) -> ())?
@IBOutlet var latitudePicker: UIPickerView!
var row: RowOf<CLLocationDegrees>!
var completionCallback: ((UIViewController) -> ())?
...
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let degrees = latitudePicker.selectedRow(inComponent: 0)
let minutes = latitudePicker.selectedRow(inComponent: 1)
let seconds = latitudePicker.selectedRow(inComponent: 2)
let negative = latitudePicker.selectedRow(inComponent: 3) == 1
self.row?.value = (Double(degrees) + Double(minutes) / 60.0 + Double(seconds) / 3600.0) * (negative ? -1 : 1)
}
在Eureka 4.3中,它停止工作。这给我一个错误,说LatitudeSelectorController
无法转换为SelectorViewController
。
我试图通过更改PresentationMode
来解决此问题:
presentationMode = PresentationMode.segueName(segueName: "selectLatitude", onDismiss: nil)
已成功显示VC,但是我注意到row
属性为nil。这意味着无论我在VC中选择什么,该行的值都不会更改。
我还尝试使LatitudeSelectorController
从SelectorRowController
继承:
class LatitudeSelectorController: SelectorViewController<SelectorRow<PushSelectorCell<Double>>>
,并恢复为使用PresentationMode.show
。
这次,row
不是零,但是整个VC都被前面的某些视图覆盖,这使我的选择器视图不可见:
如何在Eureka 4.3中创建自定义演示者行?我可以不再使用TypedRowControllerType
吗?
答案 0 :(得分:0)
您可以在此处创建并相互链接两个推送行
<<< PushRow<String>() {
$0.title = "Title"
$0.tag = "title"
$0.options = ["test"]//array values
$0.value = ""
$0.selectorTitle = "Choose title"
$0.onChange { [unowned self] row in
if row.value != nil{
//generate options here for second push row
}
}
}.onPresent { from, to in
to.dismissOnSelection = true
to.dismissOnChange = true
}
<<< PushRow<String>() { row in
row.title = "new"
row.selectorTitle = "Choose new"
row.optionsProvider = .lazy({ (formViewController, completion) in
row.options = //give new options here
completion(row.options)
})
}.onPresent { from, to in
to.dismissOnSelection = true
to.dismissOnChange = true
to.selectableRowCellUpdate = { cell, row in
//get the selected value here(row.selectableValue!) // customization
}
}