[英]Creating a segue programmatically without a storyboard
嘗試為我的注冊按鈕創建一個序列,該按鈕將把用戶發送到允許他們在我的數據庫中注冊的頁面。
通常,我制作一個按鈕和一個按鈕目標,該按鈕通過功能執行一些操作。
我們可以使該功能在 PROGRAMMATICALLY
上進行選擇嗎,介意您根本沒有使用情節提要嗎?
代碼段:
lazy var registerButton: UIButton = {
let rButton = UIButton(type: .system)
rButton.frame = CGRect(x: 210, y: 600, width: 100, height: 50)
rButton.setTitle("REGISTER", for: .normal)
rButton.backgroundColor = UIColor.white
rButton.translatesAutoresizingMaskIntoConstraints = false
rButton.setTitleColor(UIColor.black, for: .normal)
rButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
rButton.layer.cornerRadius = 20
rButton.layer.borderWidth = 2
rButton.addTarget(self, action: #selector(regSegue), for: .touchUpInside)
return rButton
}()
// will segue for me
func regSegue(){
}
我假設您在單詞page的意思是一個ViewController
。 因此,請在func regSegue(){...}
初始化ViewController
並使用present(_:animated:completion:)
方法進行present(_:animated:completion:)
。
例:
func regSegue(){
let page = PageViewController()
present(page, animated: true, completion: nil)
}
您無需情節提要即可輕松實現此目的。首先,需要初始化需要顯示的viewcontroller,然后提供view controller。
let vc: MyViewController = MyViewController()
self.presentViewController(vc, animated: true, completion: nil)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.