1

I am trying to switch from a View (a totally normal view) to another view (also normal) programmable. Here is my already existing Code:

- (IBAction)login:(id)sender {


if([_username.text isEqualToString:name] && [_password.text isEqualToString:pw])    {


    DashboardViewController *destinationController = [[DashboardViewController alloc] init];
    [self.navigationController pushViewController:destinationController animated:YES];

}else   {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Wrong Username or Password!"
                                                          message:@"Sorry."
                                                         delegate:nil
                                                cancelButtonTitle:@"Okay"
                                                otherButtonTitles:nil, nil];
        [message show];
        _password.text = nil;
    }
}

So, I want to get directed to my DashboardViewController. If I try this code, a black, empty View is shown. What is wrong with it?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kitzng
  • 105
  • 1
  • 9
  • Do you have a xib called DashboardViewController.xib or does DashboardViewController create it's own view in loadview ? It seems like maybe you aren't loading a view. – Peter Willsey Aug 28 '13 at 18:32
  • I am using a storyboard (no nib files). Abdullah Shafique's answer was really helpful! – Kitzng Aug 29 '13 at 12:02

1 Answers1

1

I recently had the same problem! Here is the solution I used:

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
DashboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"id"];
[self.navigationController pushViewController:viewController animated:YES];

MainStoryboard should be the name of your storyboard and id should be the View Controller ID which you can set in the storyboard.

Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70