Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIStoryboardSegue versus presentviewcontroller?

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

like image 614
Paulo Sigales Avatar asked May 12 '14 08:05

Paulo Sigales


1 Answers

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.

like image 149
Fogmeister Avatar answered Nov 07 '22 07:11

Fogmeister