[英]How to set root view controller for a navigation controller in swift without storyboard id. And navigate to other view Only with viewcontroller name
[英]How to navigate from one ViewController to Other Programatically, without Storyboard in Swift 2.0
我有一個位於超級視圖上的按鈕:
let buttonSignUp = UIButton()
self.view.addSubview(buttonSignUp)
當我按下這個按鈕時,我想去另一個視圖控制器場景。
首先添加按鈕 TouchUpInside-event 並將其綁定到選擇器
buttonSignUp(self, action: "pressed:", forControlEvents: .TouchUpInside)
然后實現方法“pressed”,如下所示:
func pressed(sender: UIButton!) {
let vc = UIViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
這假設您的 ViewController 在 NavigationController 中!
如果您想以模態方式呈現視圖,您可以這樣做:
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.