Ios 如何切换到现有的非导航控制器视图?

Ios 如何切换到现有的非导航控制器视图?,ios,viewcontroller,switching,Ios,Viewcontroller,Switching,我正在尝试从一个视图(完全正常的视图)切换到另一个视图(也是正常的)。以下是我已经存在的代码: - (IBAction)login:(id)sender { if([_username.text isEqualToString:name] && [_password.text isEqualToString:pw]) { DashboardViewController *destinationController = [[DashboardViewContr

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

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

因此,我想直接转到我的
仪表板视图控制器
。如果我尝试此代码,将显示一个黑色的空视图。有什么问题吗?

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

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

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

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

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

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

您是否有名为DashboardViewController.xib的xib,或者DashboardViewController是否在loadview中创建了自己的视图?似乎你没有加载视图。我使用的是故事板(没有nib文件)。阿卜杜拉·沙菲克的回答真的很有帮助!是否有名为DashboardViewController.xib的xib,或者DashboardViewController是否在loadview中创建自己的视图?似乎你没有加载视图。我使用的是故事板(没有nib文件)。阿卜杜拉·沙菲克的回答真的很有帮助!成功了!!非常感谢。你无法相信我有多幸福D@KITZNG您是否正在使用[self.navigationController pushViewController:viewController动画:是];非常感谢。我已经修好了!这真是个愚蠢的问题。。我只开发了几个星期:-)它成功了!!非常感谢。你无法相信我有多幸福D@KITZNG您是否正在使用[self.navigationController pushViewController:viewController动画:是];非常感谢。我已经修好了!这真是个愚蠢的问题。。我只开发了几周:-)