簡體   English   中英

如何在Eureka 4.3中使用TypedRowControllerType創建自定義演示者行?

[英]How can I use TypedRowControllerType to create a custom presenter row in Eureka 4.3?

我正在將一個舊項目遷移到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了嗎?

在這里,您可以創建和鏈接兩個推送行

<<< 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
                }
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM