1

我试图从一个视图(一个完全正常的视图)切换到另一个可编程的视图(也是正常的)。这是我已经存在的代码:

- (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;
    }
}

所以,我想定向到我的DashboardViewController. 如果我尝试此代码,则会显示一个黑色的空视图。它有什么问题?

4

1 回答 1

1

我最近遇到了同样的问题!这是我使用的解决方案:

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

MainStoryboard应该是您的故事板的名称,并且id应该是您可以在故事板中设置的视图控制器 ID。

于 2013-08-28T18:33:43.090 回答