简体   繁体   English

为什么不'self.navigationController?.pushViewController(mainPage,animated:true)'工作?

[英]Why doesn’t 'self.navigationController?.pushViewController(mainPage, animated: true)' work?

I am making a basic app that lets users sign up and login and they will be directed to the main page which has horizontal scrolling and paging enabled. 我正在制作一个基本的应用程序,让用户注册和登录,他们将被定向到主页面,该主页面启用了水平滚动和分页。 The main view has 3 views which you can swipe left or right to go to the other pages. 主视图有3个视图,您可以向左或向右滑动以转到其他页面。 Here is the code where I set the root view controller. 这是我设置根视图控制器的代码。 NOTE: Only if the user has logged in this view controller will be displayed. 注意:仅当用户已登录此视图控制器时才会显示。

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()

        window = UIWindow(frame: UIScreen.main.bounds)

        let homeScreen = MainScreen()
        let navBar = UINavigationController(rootViewController: homeScreen)
        window?.rootViewController = navBar
        window?.makeKeyAndVisible()


        return true
    }
}

I want to display the main page once the user logs in, but the main page doesn't get displayed. 我想在用户登录后显示主页面,但主页面不会显示。 Here is the code when the user taps on the login button, I've only given the necessary code: 这是用户点击登录按钮时的代码,我只给出了必要的代码:

// User found and verified, go to main page
let mainPage = MainScreen()
self.navigationController?.pushViewController(mainPage, animated: true)

The pushViewController doesn't work. pushViewController不起作用。

确保在推送视图控制器之前,根视图控制器必须是导航视图控制器,否则它将无法工作。

thanks for your answers but I figured it out. 谢谢你的答案,但我想通了。

// User found and verified, go to main page
let mainPage = MainScreen()
let navController = UINavigationController(rootViewController: mainPage)
self.present(navController, animated: true, completion: nil)

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

相关问题 为什么self.navigationController pushViewController不起作用? - Why won't self.navigationController pushViewController work? 使用 self.navigationController 时出现问题?.pushViewController(newViewController, animated: true) - Problems using self.navigationController?.pushViewController(newViewController, animated: true) self.navigationController pushViewController:动画:给我一个黑屏 - self.navigationController pushViewController: animated: gives me a black screen [self.navigationController pushViewController:ngView animated:YES]; 不工作 - [self.navigationController pushViewController:ngView animated:YES]; not working self.navigationController pushViewController 不工作 - self.navigationController pushViewController not working [self.navigationController popViewControllerAnimated:YES]; 在委托回调中不起作用 - [ self.navigationController popViewControllerAnimated:YES ]; doesn't work in delegate callback self.navigationController?.pushViewController 不工作 Swift - self.navigationController?.pushViewController not Working Swift self.navigationController pushViewController未将控制器添加到堆栈 - self.navigationController pushViewController not adding controller to stack 关于self.navigationController pushViewController(IOS) - about self.navigationController pushViewController (IOS) NavigationController pushViewController不起作用 - NavigationController pushViewController doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM