将 UIViewcontroller 推送到 UINavigation Controller

push UIViewcontroller to UINavigation Controller

我有登录屏幕但忘记了密码screen.forgot密码屏幕连接到导航控制器但我的登录屏幕没有连接到导航控制器所以如何将登录屏幕移动到忘记屏幕

这是我的代码

forgotpasswod *secondViewController =
    [self.storyboard instantiateViewControllerWithIdentifier:@"forgotpasswodpage"];

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

你可以展示View controller

let vc : ForgotPassword = storyboard.instantiateViewControllerWithIdentifier("forgotView") as  ForgotPassword

let navigationController = UINavigationController(rootViewController: vc)

self.presentViewController(navigationController, animated: true, completion: nil)

对于对象 c

 ForgotPassword *secondViewController =
[self.storyboard instantiateViewControllerWithIdentifier:@"forgotpasswodpage"];

UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[self presentViewController:controller animated:YES completion:nil];

如果您想将 ViewController 移动到导航 Viewcontroller 而不是使用 presentView 控制器。

将此代码粘贴到您的操作方法中

- (IBAction)forgotpassword:(id)sender {

    forgotpasswod *secondViewController =
    [self.storyboard instantiateViewControllerWithIdentifier:@"forgotpasswodpage"];

    UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:secondViewController];
    [self presentViewController:controller animated:YES completion:nil];
}

当您尝试此代码时,您还可以更改导航栏颜色

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        // iOS 6.1 or earlier
        self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"#37B578"];
    } else {
        // iOS 7.0 or later
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#37B578"];
        self.navigationController.navigationBar.translucent = NO;
    }

好的,试试这个代码,然后告诉我发生了什么...

这里的问题是您的导航控制器是 nil,因为初始控制器 (LoginViewController) 没有像 forgorpassordViewController 那样嵌入到导航控制器中。

为什么不将 loginInViewController 嵌入到 navigationController 中并将 ForgotViewController 上的标识符设置为 'forgotpasswodpage',就像您所做的那样

然后你就完全按照你的代码做事

forgotpasswod *secondViewController =
    (forgotpasswod *)[self.storyboard instantiateViewControllerWithIdentifier:@"forgotpasswodpage"];

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

另外我更喜欢你使用 [self.navigationController showViewController:secondViewController animated:YES];

点击忘记密码,只需从您的故事板中创建导航控制器即可成为您应用 window 的根视图控制器。它会自动加载附加到您的导航控制器的视图。