Eureka: How to develop custom push row in Eureka 4.x?

Created on 11 Oct 2017  路  4Comments  路  Source: xmartlabs/Eureka

The documentation is:

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
                _ = vc.navigationController?.popViewController(animated: true)
        })
    }
}

but this code in 4.x couldn't get compiled.

custom row SelectorRow

Most helpful comment

@chappejw Check my solution in #1282, it's the same issue. SelectorRow did became more specialized and uses SelectorViewController for VC and lost functionality just to present ViewController.

All 4 comments

I'm looking for a solution to this as well. The code below errors on ControllerProvider.callback with error message:
Cannot convert value of type 'ControllerProvider' to expected argument type 'ControllerProvider<_>'

public final class GeolocationRow : SelectorRow<PushSelectorCell<CLLocation>>, RowType {
    public required init(tag: String?) {
        super.init(tag: tag)
        presentationMode = .show(controllerProvider: ControllerProvider.callback
        {
            return MapViewController() { _ in }
            }, onDismiss: { vc in
                let _ = vc.navigationController?.popViewController(animated: true)
        })

        displayValueFor = {
            guard let location = $0 else { return "" }
            let fmt = NumberFormatter()
            fmt.maximumFractionDigits = 4
            fmt.minimumFractionDigits = 4
            let latitude = fmt.string(from: NSNumber(value: location.coordinate.latitude))!
            let longitude = fmt.string(from: NSNumber(value: location.coordinate.longitude))!
            return  "\(latitude), \(longitude)"
        }
    }
}

I'm using Xcode 9 and Eureka 4.0.1

screen shot 2017-10-11 at 5 28 07 pm

public final class GeolocationRow : Row<PushSelectorCell<CLLocation>>, RowType {
    public required init(tag: String?) {
        super.init(tag: tag)
        displayValueFor = {
            guard let location = $0 else { return "" }
            let fmt = NumberFormatter()
            fmt.maximumFractionDigits = 4
            fmt.minimumFractionDigits = 4
            let latitude = fmt.string(from: NSNumber(value: location.coordinate.latitude))!
            let longitude = fmt.string(from: NSNumber(value: location.coordinate.longitude))!
            return  "\(latitude), \(longitude)"
        }
    }

    override func customDidSelect() {
        super.customDidSelect()
        guard !isDisabled else { return }

        let vc = MapViewController() { _ in }
        vc.row = self
        cell.formViewController()?.navigationController?.pushViewController(vc, animated: true)
        vc.onDismissCallback = { _ in
            vc.navigationController?.popViewController(animated: true)
        }
    }
}

Thanks for the response @KevinGong2013. If you have a few minutes would you mind leaving a couple comments to explain this change. I will certainly test this tomorrow morning. Thanks for your time.!

@chappejw Check my solution in #1282, it's the same issue. SelectorRow did became more specialized and uses SelectorViewController for VC and lost functionality just to present ViewController.

Was this page helpful?
0 / 5 - 0 ratings