5

I am migrating an old project to Swift 4, so naturally I also updated to Eureka 4.3.

In the old project, there is a custom row called LatitudeSelectorRow that presents a LatitudeSelectorController.

LatitudeSelectorRow used to look like this:

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

And LatitudeSelectorController used to look like this:

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

In Eureka 4.3, that stopped working. It gives me an error saying that LatitudeSelectorController cannot be converted to a SelectorViewController.

I tried to work around this by changing the PresentationMode:

presentationMode = PresentationMode.segueName(segueName: "selectLatitude", onDismiss: nil)

The VC is successfully shown, but I noticed that the row property is nil. This means that no matter what I select in the VC, the row's value won't be changed.

I also tried to make LatitudeSelectorController inherit from SelectorRowController:

class LatitudeSelectorController: SelectorViewController<SelectorRow<PushSelectorCell<Double>>>

and reverted back to using PresentationMode.show.

This time, row is not nil, but the whole VC is covered by some view at the front, making my picker view invisible:

enter image description here

How can I create a custom presenter row in Eureka 4.3? Can I not use TypedRowControllerType anymore?

Sweeper
  • 213,210
  • 22
  • 193
  • 313

1 Answers1

0

Here you can create and inter link two push rows

<<< 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
                }
            }
Preetika
  • 702
  • 8
  • 21
  • I don't understand how this answers the question. My problem is that I can't present my custom VC properly. It either crashes with a type conversion error or my view is hidden behind something weird, as I said in the question. – Sweeper Dec 14 '18 at 17:50