Someone can explain the difference between use of UIStoryboardSegue modal
versus programmatically presentViewController
?
Use UIStoryboardSegue
is only to facilitate? Or have some performance benefit?
Thank you
Performance wise there is no real difference.
The main difference is where the new view controller is created.
With the storyboard segue the object is unarchived from the storyboard before it is presented.
In code you would have to create the new view controller like...
ModalViewController *modal = [[ModalViewController alloc] init];
before you present it...
[self presentViewController:modal animated:YES completion:nil];
Both of them allow you to inject properties in different ways too.
Using code you would add the following above...
// depends on property type etc...
modal.someProperty = @"someValue";
When using a segue you would do this...
- (void)prepareForSegue:(UIStoryBoardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"modalSegue"]) {
// the view controller is already created by the segue.
// just grab it here first
ModalViewController *controller = segue.destinationViewController;
controller.someProperty = @"someValue";
}
}
Is there a difference?
Not really, just personal preference and some approaches lend themselves more easily to certain design patterns and usages. The more you use both the more you'll learn which approach you prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With