0

I have a 2 viewControllers in my storyboards, I am making a login (all with objective C), when the credentials are OK I need to show another screen (and send data if is possible), but I found examples with segues and take the button to do it, I dont want to set the button to the segue because when I push it the another screen will be shown

I need to show the new screen only on the condition "if credentials are ok"

ChrisM
  • 1,576
  • 6
  • 18
  • 29
  • If i remember you must use something like prepareforseque. See https://stackoverflow.com/questions/7864371/how-to-pass-prepareforsegue-an-object – baliman Nov 05 '19 at 17:38

2 Answers2

0

You can create a seque, give it some id and then call like this when you need to:

[self performSegueWithIdentifier:@"loginSeque" sender:self];
Pavel Lint
  • 3,252
  • 1
  • 18
  • 18
  • but it not works because if I define the segue from the button to the next screen, when I push the button automatically will show the screen, and If I define the segue from the view controller to the other viewcontroller does not work, or I am doing something wrong? – billieiosdev Nov 05 '19 at 17:47
  • You should define a seque from first view controller to the second, not on the button. Then it will work, just give it the right ID and make sure you call it when needed! – Pavel Lint Nov 05 '19 at 17:48
  • it works! but, the new screen appear like a modal, so i can drag and close it, is there a way to show the second screen and replace the first one, without posibility to return, please – billieiosdev Nov 05 '19 at 17:56
  • you could wrap both into a NavigationController, then it wouldn't appear as a modal – Pavel Lint Nov 05 '19 at 18:00
  • I did it, in presentation I set "full screen", thanks for the help – billieiosdev Nov 05 '19 at 18:03
0

You can create login button action manually and try below code.

- (IBAction)LoginButtonAction:(id)sender {

    if ([self validated]) {    // check login validation on "validate" method. 

         UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
         HomeVC *home = [story instantiateViewControllerWithIdentifier:@"HomeVC"];

         UINavigationController *NavigationController = [[UINavigationController alloc] initWithRootViewController: home];    // for set HomeVC as a root view controller.

         [[UIApplication sharedApplication].keyWindow setRootViewController:NavigationController];
    }
}
Nick
  • 875
  • 6
  • 20