Eureka: How can I use Eureka forms in a view controller that is not a subclass of `FormViewController`

Created on 8 Nov 2015  ·  3Comments  ·  Source: xmartlabs/Eureka

How can I use Eureka forms in a view controller that is not a subclass of FormViewController

Most helpful comment

@mtnbarreto Is it possible to implement FormViewController as a protocol with default behavior that extend UIViewController so that view controllers that are not subclasses of FormViewController can conform to it?

Consider this use case. I want all view controllers in my app have some base common behavior and only some of this controllers will contain forms. If FormViewController was a protocol it was possible to use subclasses of a base view controller for all controllers and controllers with forms in them conform to the protocol.

The other possible approach is the approach used by FXForms, see https://github.com/nicklockwood/FXForms#displaying-a-form-advanced
(You can inherit from FXFormViewController or use a plain UIViewController and assign it a form controller and a tableview)

All 3 comments

You must extend from FormViewController. FormViewController is nothing else than a extension of UIViewController that adds some behaviour to display the form properly so this should not be a problem.

Regards

@mtnbarreto Is it possible to implement FormViewController as a protocol with default behavior that extend UIViewController so that view controllers that are not subclasses of FormViewController can conform to it?

Consider this use case. I want all view controllers in my app have some base common behavior and only some of this controllers will contain forms. If FormViewController was a protocol it was possible to use subclasses of a base view controller for all controllers and controllers with forms in them conform to the protocol.

The other possible approach is the approach used by FXForms, see https://github.com/nicklockwood/FXForms#displaying-a-form-advanced
(You can inherit from FXFormViewController or use a plain UIViewController and assign it a form controller and a tableview)

@abbasmousavi Couldn't you achieve the same thing by building your common behavior into a protocol, and creating a SpecializedFormViewController and a SpecializedViewController?

You could even avoid duplications with protocol extensions

Was this page helpful?
0 / 5 - 0 ratings