Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift:如何在导航控制器之后访问第二视图?_Swift_Navigationcontroller_Tabbed - Fatal编程技术网

Swift:如何在导航控制器之后访问第二视图?

Swift:如何在导航控制器之后访问第二视图?,swift,navigationcontroller,tabbed,Swift,Navigationcontroller,Tabbed,我对swift真的很陌生,目前正在为一个琐事应用程序做一个项目。现在我有了它,在按下开始按钮后,它会将当前视图控制器推到一边,并向用户显示一个新的视图(vc),但我不确定如何/在何处向用户在按下开始按钮后看到的新视图(vc)添加文本字段和按钮 let vc = UIViewController() vc.view.backgroundColor = .red navigationController?.pushViewC

我对swift真的很陌生,目前正在为一个琐事应用程序做一个项目。现在我有了它,在按下开始按钮后,它会将当前视图控制器推到一边,并向用户显示一个新的视图(vc),但我不确定如何/在何处向用户在按下开始按钮后看到的新视图(vc)添加文本字段和按钮


       
       let vc = UIViewController()
       vc.view.backgroundColor = .red
       
       navigationController?.pushViewController(vc, animated: true) 

您必须创建另一个包含UI的视图控制器

   class SecondViewController: UIViewController {
       private let textView = UITextView()
       
       func viewDidLoad() {
           super.viewDidLoad()
           
           // Add text view with auto layout
           view.addSubview(textView)
           textView.translatesAutoresizingMaskIntoConstraints = false
           textView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
           textView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
           textView.heightAnchor.constraint(equalToConstant: 44).isActive = true
       }
   }
然后,当尝试推送新的视图控制器时,请使用此
SecondViewController

   let vc = SecondViewController()
   vc.view.backgroundColor = .red
   
   navigationController?.pushViewController(vc, animated: true) 

可以使用指定的标识符声明视图控制器

let vc = UIStoryboard.init(name: "Authentication", bundle: Bundle.main).instantiateViewController(withIdentifier: "Login") as? LoginVC
self.navigationController?.pushViewController(vc!, animated: true)