I recently tried working with the MainStoryboard.storyboard within Xcode and so far It\'s going pretty good and I\'m wondering why I\'ve never used it before. While playing
I would just create a method which does the custom data loading.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"];
[myViewController loadCustomData:myCustomData];
[self presentViewController:myViewController animated:YES completion:nil];
If all your initWithCustomData
method does is set one instance variable, you should just set it manually (no custom inits or extra methods required):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"];
myViewController.iVarData = myCustomData;
[self presentViewController:myViewController animated:YES completion:nil];
You can instantiate viewcontroller in -init method.
- (instancetype)init
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
self = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
if(self)
{
//default initialization
}
return self;
}
and the in your custom init method
- (instancetype)initWithImages:(NSArray *)images
{
self = [self init];
if(self)
{
self.images = images;
}
return self;
}
My version:
- (instancetype)initWithData (NSArray *)someData
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
self = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
if(self)
{
//default initialization
}
return self;
}
...one initializer ;)