navigationcontroller无法正常工作,请转到另一个视图控制器?

问题描述 投票:-1回答:1

我有两个按钮,分别是登录和注册按钮,当我要点击我的登录按钮时,我以编程方式对未使用情节提要的UI进行编码,因此不会转到LoginController这是我的代码。是因为新的SceneDelegate吗?

    import UIKit

    class ViewController: UIViewController{
         let loginButton = UIButton()
         let signUpButton = UIButton()

    override func viewDidLoad(){
        super.viewDidLoad()

         setupLoginButton()
         setupSignUpButton()
         view.backgroundColor = .black
    }

func setupLoginButton(){
   loginButton.applyDesign()
   loginButton.setTitle("Login", for: .normal)

   loginButton.addTarget(self, action: #selector(loginButtonTapped), for: .touchUpInside)

   view.addSubview(loginButton)
   loginButtonConstraints()
}

@objc func loginButtonTapped(){
 let nextScreen = LoginController()
 navigationController?.pushViewController(nextScreen, animated: true)
}
swift xcode
1个回答
0
投票
        let nextScreen = LoginController()
        let nextVC = UINavigationController(rootViewController: nextScreen)
        nextVC.modalPresentationStyle = .fullScreen
        self.present(nextVC, animated: true, completion: nil)

尝试一下,它将起作用。

© www.soinside.com 2019 - 2024. All rights reserved.