Eureka: Help creating simple Custom Presenter Row

Created on 11 Oct 2016  路  5Comments  路  Source: xmartlabs/Eureka

Eureka: 1.7 (Swift 2 Branch)
XCode: 7.3.1 (Swift 2.2)
iOS Target: 9.0

Hi, I was wondering if I could get some help writing a simple Custom Presenter Row. I am attempting to initialize and present a new controller through one of the rows in my form.

I do not need the custom view to report anything to the form, I just want it to give access to the view like so:
row

`

I started with the example in the documentation, but quickly got lost as I changed it to initialize my custom controller:

public final class CustomPushRow<T: Equatable> : SelectorRow<T, PushSelectorCell<T>, SelectorViewController<T>>, RowType {

    public required init(tag: String?) {
        super.init(tag: tag)
        presentationMode = .Show(controllerProvider: ControllerProvider.Callback {
            let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
            let vc: DeviceDetailSettingsViewController = mainStoryboard.instantiateViewControllerWithIdentifier("deviceDetailSettingsView") as! DeviceDetailSettingsViewController
            return vc // ERROR
            }, completionCallback: { vc in
                vc.navigationController?.popViewControllerAnimated(true)
        })
    }
}

However, this produces the following error:
.../ActionParametersViewController.swift:323:20: Cannot convert return expression of type 'DeviceDetailSettingsViewController' to return type 'SelectorViewController<T>'

My initial idea was to have my controller implement SelectorViewController but this seems to be overly complicated to just do the simple action of pushing my view controller onto the navigation controller, so the user can pop it with the Back button.

Anyone have any pointers on how to achieve this? Any help is appreciated.

PS: Using a ButtonRow is not an option for me as I'd like it to have the PresenterRow layout without the value preview (since I wont be returning a value to the form for this "row")

Stack Overflow onPresent PushRow awaiting response

Most helpful comment

I know this is a closed issue, but after a hair-pulling morning I wanted to share some notes in case it helps someone else

I needed to create a custom row to present a custom view. Most examples are either a custom row, OR a custom view, but there is a hint in the README: "For example a CustomPushRow can be defined like this: [...] You can place your own UIViewController instead of SelectorViewController and your own cell instead of PushSelectorCell."

This fantastic framework pushes the boundaries of XCode for understanding and reporting what is wrong amongst all of the templates and protocols. Here are some of the many incorrect errors I got when trying to create a Custom Push Row with a Custom Cell and Custom View Controller:
'super' members cannot be referenced in a root class
Type 'CustomPushRow' does not conform to protocol 'Taggable'
Type 'CustomPushRow' does not conform to protocol 'BaseRowType'
Type 'CustomPushRow' does not conform to protocol 'TypedRowType'

And my hint for anyone who finds this doing desperate Issues searches: Your custom view controller needs to conform to the protocol TypedRowControllerType. This appears to only be documented in the framework source.

To recap:

final class CustomCell: Cell<YOUR CUSTOM TYPE>, CellType {
    // IBOutlets or whatever you need for your cell
    public override func setup() { }
    public override func update() { }
}

final class CustomPushRow: SelectorRow<CustomCell, CustomViewController>, RowType {
    public required init(tag: String?) {
        super.init(tag: tag)

        cellProvider = CellProvider<CustomCell>(nibName: "CustomCell")
        presentationMode = .show(controllerProvider: ControllerProvider.callback {
            return CustomViewController() // mine is another FormViewController, so no NIB or Storyboard
            }, onDismiss: { vc in
                _ = vc.navigationController?.popViewController(animated: true)
        })
    }
}

class CustomViewController: TypedRowControllerType /*, FormViewController*/ {
    // these are required to conform to TypedRowControllerType
    public var row: RowOf<YOUR CUSTOM TYPE>!
    public var onDismissCallback : ((UIViewController) -> ())?
}

All 5 comments

Hi,

Although this is not what you exactly need, please have a look at, http://stackoverflow.com/questions/39448586/how-to-present-a-viewcontroller-using-a-row-in-eureka-forms

Let me know if it doesn't make sense

Your CustomPushRow says it will use a SelectorViewController but in the presentationMode it returns a DeviceDetailSettingsViewController.
You need to change the definition of your row to something like this:
public final class CustomPushRow : SelectorRow<CustomCell, DeviceDetailSettingsViewController>, RowType

@Laptopmini there is a button row with present functionality: ButtonRowWithPresent

form +++ Section() 
                 <<< ButtonRowWithPresent<YourPresentedViewController>() {
                                $0.presentationMode = ......
                         }

Let me know if that works for you...

Thanks @mtnbarreto . I revisited the subject and managed to produce the result I needed with the following:

ButtonRowWithPresent<String, ColorPickerViewController>() {
                $0.title = "Device Color"
                $0.presentationMode = PresentationMode<ColorPickerViewController>.Show(controllerProvider: ControllerProvider.Callback {
                    let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
                    let vc = mainStoryboard.instantiateViewControllerWithIdentifier("colorPickerViewController") as! ColorPickerViewController
                    vc.delegate = self
                    return vc
                }, completionCallback: nil)
            }

I know this is a closed issue, but after a hair-pulling morning I wanted to share some notes in case it helps someone else

I needed to create a custom row to present a custom view. Most examples are either a custom row, OR a custom view, but there is a hint in the README: "For example a CustomPushRow can be defined like this: [...] You can place your own UIViewController instead of SelectorViewController and your own cell instead of PushSelectorCell."

This fantastic framework pushes the boundaries of XCode for understanding and reporting what is wrong amongst all of the templates and protocols. Here are some of the many incorrect errors I got when trying to create a Custom Push Row with a Custom Cell and Custom View Controller:
'super' members cannot be referenced in a root class
Type 'CustomPushRow' does not conform to protocol 'Taggable'
Type 'CustomPushRow' does not conform to protocol 'BaseRowType'
Type 'CustomPushRow' does not conform to protocol 'TypedRowType'

And my hint for anyone who finds this doing desperate Issues searches: Your custom view controller needs to conform to the protocol TypedRowControllerType. This appears to only be documented in the framework source.

To recap:

final class CustomCell: Cell<YOUR CUSTOM TYPE>, CellType {
    // IBOutlets or whatever you need for your cell
    public override func setup() { }
    public override func update() { }
}

final class CustomPushRow: SelectorRow<CustomCell, CustomViewController>, RowType {
    public required init(tag: String?) {
        super.init(tag: tag)

        cellProvider = CellProvider<CustomCell>(nibName: "CustomCell")
        presentationMode = .show(controllerProvider: ControllerProvider.callback {
            return CustomViewController() // mine is another FormViewController, so no NIB or Storyboard
            }, onDismiss: { vc in
                _ = vc.navigationController?.popViewController(animated: true)
        })
    }
}

class CustomViewController: TypedRowControllerType /*, FormViewController*/ {
    // these are required to conform to TypedRowControllerType
    public var row: RowOf<YOUR CUSTOM TYPE>!
    public var onDismissCallback : ((UIViewController) -> ())?
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

tc picture tc  路  3Comments

Tomas1405 picture Tomas1405  路  3Comments

iBearKh picture iBearKh  路  3Comments

thlbaut picture thlbaut  路  3Comments

pteasima picture pteasima  路  3Comments