0

I have already referred Storyboard - refer to ViewController in AppDelegate.

I want to ask whether it's the same viewcontroller obj as we can see in storyboard. if we code like:

    FirstViewController* fvc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"first"];
    NSLog(@"fvc=%@", fvc);
    [fvc performSegueWithIdentifier:@"go2next" sender:fvc];

as I tested, it is not the same as:

    NSLog(@"self=%@", self);
    [self performSegueWithIdentifier:@"go2next" sender:self];

From log, I can see they are not the same objs. How can I get the same view controller obj from storyboard by code?

I created two viewcontroller named(FirstViewController, SecondController) in storyboard, and add a segue between the two. I tried to use performSegueWithIdentifier to transfer to the the second page. [self performSegueWithIdentifier]works, while [fvc performSegueWithIdentifier]doesn't work.

Community
  • 1
  • 1
droughtrain
  • 257
  • 1
  • 4
  • 18

1 Answers1

0

I solved the problem at last. if I add the following lines in AppDelegate.m

FirstViewController* fvc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"first"];
self.window.rootViewController = fvc;
NSLog(@"fvc=%@", fvc);
[fvc performSegueWithIdentifier:@"go2next" sender:fvc];

It worked the same as:

NSLog(@"self=%@", self);
[self performSegueWithIdentifier:@"go2next" sender:self];
droughtrain
  • 257
  • 1
  • 4
  • 18