Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initWithCoder support #32

Closed
wefish opened this issue May 16, 2014 · 2 comments
Closed

initWithCoder support #32

wefish opened this issue May 16, 2014 · 2 comments

Comments

@wefish
Copy link

wefish commented May 16, 2014

I'm using segues on my project. Navigation is performed using code like

[self performSegueWithIdentifier:@"editData" sender:self];

And the data to be edited is asigned to destination view controller on the prepareForSeguemethod

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"editWorkerProfile"])
    {
        UINavigationController* navController = [segue destinationViewController];
        MyEditorViewController *editorController = (MyEditorViewController *) [navController topViewController];
        editorController.data = dataToBeEdited;
    }
}

The destination ViewController is initialized using "initWithCoder" and form structure is created on the "viewDidLoad" (Because data property is assigned after initialization).

With te "1.0.0" version of XLForm I used a "trick" like this on destination ViewController:

- (id)initWithCoder:(NSCoder*)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        XLFormDescriptor * form  = [XLFormDescriptor formDescriptorWithTitle:@"work profile"];
        return [super initWithForm:form]; // Second init... it works with XLFrom 1.0.0!!!
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Form content is built after initialization
    [self buildForm: self.form withData: self.data]; 
}

With the actual git XLForm version this code is not working anymore: form appears empty...

¿What's the correct way to use XLForm with storyboard & segues?

@mtnbarreto
Copy link
Member

Hey @wefish , you can extend XLFormViewController and configure the form DSL from XLFormViewController subclass, take a look at ExamplesFormViewController class, this VC is used by iPhoneStoryboard.

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard" bundle:nil];
    [self.window setRootViewController:[storyboard instantiateInitialViewController]];

In case you don't want to extend XLFormViewController, you can set up the form DSL (XLFormDescriptor) using @property XLFormDescriptor * form; property,.

I think you can use this property either after the class initialization or from prepareForSegue.


Your [super initWithForm:form] invocation from - (id)initWithCoder:(NSCoder*)aDecoder is wrong, don't do that. This is a helper initializer not intended to be used with storyboards, it calls [super initWithStyle:style].


I've removed awakeFromNib and added initWithCoder to XLFormViewController.

Let me know if this helps.

@wefish
Copy link
Author

wefish commented May 19, 2014

Thanks Martin, with new initializer initWithCoder all is working ok.

this is my actual code:

- (id)initWithCoder:(NSCoder*)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        XLFormDescriptor * form  = [XLFormDescriptor formDescriptorWithTitle:@"my title"];
        self.form = form;
    }
    return self;
}

form sections and rows are added on "viewDidLoad".

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants