简体   繁体   English

iOS NavigationController pushViewController不起作用

[英]iOS navigationController pushViewController not working

I have a storyboard with a UINavigationController . 我有一个带有UINavigationController的情节UINavigationController The root view controller of the navigation controllers is called rootViewController. 导航控制器的根视图控制器称为rootViewController。

I am trying to programmatically change the view controller (depending on other conditions) to another view controller called loginViewController . 我试图以编程方式将视图控制器(取决于其他条件)更改为另一个名为loginViewController视图控制器。

I am trying to do this in the viewDidLoad from the rootViewController like this: 我正在尝试从像这样的rootViewController在viewDidLoad做到这一点:

- (void)viewDidLoad
{

    [super viewDidLoad];

    loginViewController *viewController = [[loginViewController alloc] init];

    [self.navigationController pushViewController:viewController animated:YES];

}

I am not getting any errors but it's not working. 我没有收到任何错误,但是没有用。

It just loads the navigation controller with the top nav back button but the rest of the screen is black. 它只是使用顶部导航后退按钮加载导航控制器,但屏幕的其余部分为黑色。 It's like it's not loading any view controller. 就像没有加载任何视图控制器一样。

I am trying to figure out what I am doing wrong. 我试图弄清楚我在做什么错。

Any help with this would be great. 任何帮助都会很棒。

Thanks 谢谢

First add loginViewController class in storyboard and and connect ViewController class to loginViewController class and give identifier name as "identifier_Name". 首先在情节提要中添加loginViewController类,然后将ViewController类连接到loginViewController类,并将标识符名称命名为“ identifier_Name”。

- (void)viewDidLoad
{

    [super viewDidLoad];
    [self performSegueWithIdentifier:@"identifier_Name" sender:nil];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"identifier_Name"])
    {
        loginViewController *viewController = [segue destinationViewController];
    }
}

If you're using storyboard, create your login view in the storyboard, link your rootVC to the loginVC with a segue, choose an identifier (for example: "goToLogin"). 如果使用情节提要,请在情节提要中创建登录视图,并使用segue将rootVC链接到loginVC,然后选择一个标识符(例如:“ goToLogin”)。 and then to go in the login view, and use: 然后进入登录视图,并使用:

[self performSegueWithIdentifier:@"goToLogin" sender:self];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM