[英]How to navigate from one ViewController to Other Programatically, without Storyboard in Swift 2.0
I have a button which is located on superview:我有一个位于超级视图上的按钮:
let buttonSignUp = UIButton()
self.view.addSubview(buttonSignUp)
When I press this button I want to go to another view controller scene.当我按下这个按钮时,我想去另一个视图控制器场景。
First add the buttons TouchUpInside-event and bind it to a selector首先添加按钮 TouchUpInside-event 并将其绑定到选择器
buttonSignUp(self, action: "pressed:", forControlEvents: .TouchUpInside)
Then implement the method "pressed", like this:然后实现方法“pressed”,如下所示:
func pressed(sender: UIButton!) {
let vc = UIViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
This assumes that your ViewController is in a NavigationController!这假设您的 ViewController 在 NavigationController 中!
If you instead want to present the view modally, you can do this:如果您想以模态方式呈现视图,您可以这样做:
let vc = UIViewController()
self.presentViewController(vc, animated: true) { () -> Void in
//Here you can write code that you want to run WHEN the modal present is completed
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.