![](/img/trans.png)
[英]iOS: how to add a search bar on navigation bar programmatically on a button press?
[英]How to add Navigation bar programmatically by clicking the button
我有登錄,注冊和重置viewControllers我已經將UINavigation控制器連接到登錄控制器,但是當我通過單擊諸如signup
或reset 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.