Search code examples
iosdelegatesstoryboardseguescene

iOS, Set delegate for scene without using segue


I am trying to navigate to a scene without using a segue. The code I am using looks like this:

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
MyViewController * controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
[self presentViewController:controller animated:YES completion:nil];

My problem is setting the delegate for this scene. Usually I would do the following:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Check the segue identifier
    if ([[segue identifier] isEqualToString:@"showDetail"])
    {
        [[segue destinationViewController] setDelegate:self];
    }
}

But I do not want to use segues. Can anyone please tell me how I could set the delegate for the scene?

Thanks


Solution

  • UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    DetailViewController * controller = (DetailViewController *)[storyboard instantiateViewControllerWithIdentifier:@"DetailView"];
    controller.delegate = self;
    [self presentViewController:controller animated:YES completion:nil];