initWithCoder support
wefish opened this issue · 2 comments
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 prepareForSegue
method
- (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?
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.
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!!