IOS - How to program the navigation between ViewController direct in viewDidLoad?

1

I want to navigate between the ViewController of an app by clicking a button and switching from one to another for example. I wanted to run this directly in the viewDidLoad of the ViewController1, if the user has already registered, I will send it to the secondView.

It would look something like this:

ViewController1

-(void)viewDidLoad{
    if(_cadastrado isEqualToString:@"1"){
        UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"segundaView"];
        [self presentViewController:viewController animated:YES completion:nil];
    }
}

The method when I run out of viewDidLoad works perfectly, but when I try to run it inside the viewDidLoad I can not.

    
asked by anonymous 29.02.2016 / 13:58

2 answers

1

With the @JeffersonAssis hint, I managed to include the code mentioned in the question inside the viewDidAppear method.

looks like this:

-(void) viewDidAppear:(BOOL)animated{
    if(_cadastrado isEqualToString:@"1"){
        UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"segundaView"];
        [self presentViewController:viewController animated:YES completion:nil];
    }
}

So it runs right after running the entire viewDidLoad .

    
27.03.2016 / 20:23
2

Hello, in this case it will be necessary to do this process in AppDelegate

Example This:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    // EM - Implementação da verificação do cadastro da função do Device
    NSIndexPath * indexPath;

    [PlistManager deletePlist:@"ServerControllerPWD" location:@"doc"];

    Password * passConference = [[PWDataController sharedInstance].PWData objectAtIndex:indexPath.row];

    if ([passConference.functionVC isEqualToString:@"Servidor"]) {

        ServerViewController *appStartViewController = [[ServerViewController alloc] init];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:appStartViewController];
        [navController setModalPresentationStyle:UIModalPresentationFullScreen];

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Server"];
        self.window.rootViewController = vc;

        [self.window makeKeyAndVisible];

    } else {

     nil ;

return YES;

}

This example is taking data from an object that has the data stored in a Plist.

In your case this "register" refers to that?

    
27.03.2016 / 14:13