如何切换到现有的非导航控制器 - 视图可编程?

时间:2013-08-28 18:27:41

标签: ios viewcontroller switching

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

- (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。如果我尝试此代码,则会显示一个黑色的空视图。这有什么问题?

1 个答案:

答案 0 :(得分:1)

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

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

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