如何使用UIButton切换视图控制器?这是我的代码:
@IBAction func scanAction(sender: AnyObject) {
//switch view controller
}
Run Code Online (Sandbox Code Playgroud)
当我单击"扫描"按钮时,它将转到登录表单.
我在Main.storyboard中的视图控制器是这样的

如果可以,请给我一些建议.谢谢.
Moh*_*din 15
我已经找到了答案
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
self.presentViewController(nextViewController, animated:true, completion:nil)
Run Code Online (Sandbox Code Playgroud)
一种方法是从按钮中获得模态segue.不需要IBOutlet.

编程方式:
@IBAction func scanButton (sender: UIButton!) {
performSegueWithIdentifier("nextView", sender: self)
}
Run Code Online (Sandbox Code Playgroud)
您应该添加模态segue并命名标识符.您将VC1连接到VC2.
| 归档时间: |
|
| 查看次数: |
71328 次 |
| 最近记录: |