簡體   English   中英

如何通過單擊按鈕以編程方式添加導航欄

[英]How to add Navigation bar programmatically by clicking the button

我有登錄,注冊和重置viewControllers我已經將UINavigation控制器連接到登錄控制器,但是當我通過單擊諸如signupreset password之類的按鈕轉到其他視圖控制器時,目標控制器將出現而沒有導航欄。 單擊下面的按鈕時,以編程方式幫助包含導航欄。

@IBAction func signupButton(_ sender: Any) {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "SignUpViewController") as! SignUpViewController
self.present(newViewController, animated: true, completion: nil)
}

對於顯示導航欄,您需要在UINavigationController添加SignUpViewController ,您可以直接在Storyboard中添加By

選擇SignUpViewController->編輯器菜單->嵌入->導航控制器

要么

您可以像這樣以編程方式添加

IBAction func signupButton(_ sender: Any) {
     let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
     let newViewController = storyBoard.instantiateViewController(withIdentifier: "SignUpViewController") as! SignUpViewController
     let naviCon = UINavigationController(rootViewController:newViewController)
     self.present(naviCon, animated: true, completion: nil)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM