我想要创建一个基本的iOS应用程序,有两个按钮。点击第一个按钮显示视图控制器1,点击第二个按钮显示视图控制器2。
我怎么能用快速密码来做这件事。
我将第一个按钮连接到根视图控制器上的以下代码:
@IBAction func showViewOneTapped(_ sender: Any) {
// this is where I need help I think
}我还为我想要显示的每个视图控制器创建了外壳快速文件。
发布于 2018-03-13 08:40:40
试试这个-
@IBAction func showViewOneTapped(_ sender: Any) {
let storyBoard : UIStoryboard = UIStoryboard(name: "YourStoryBoardName", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "YourIdentifierName") as! yourClassname(e.g PhoneNoDropDownViewController)
self.present(nextViewController, animated:true, completion:nil)
}
@IBAction func showViewTwoTapped(_ sender: Any) {
let storyBoard : UIStoryboard = UIStoryboard(name: "YourStoryBoardName", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "YourIdentifierName") as! yourClassname(e.g PhoneNoDropDownViewController)
self.present(nextViewController, animated:true, completion:nil)
}发布于 2018-03-13 08:39:30
像这样
let vc1 = self.storyboard?.instantiateViewController(withIdentifier: "ViewController1Identifier") as! ViewController1
self.present(vc1, animated: true, completion: nil)发布于 2018-03-13 08:53:26
试试这个
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "Login") as! LoginViewController
self.present(nextViewController, animated:true, completion:nil)

https://stackoverflow.com/questions/49251520
复制相似问题