我正在 Swift Storyboard 中為 iOS 創建一個多場景應用程式。我想在 UIViewController 中以編程方式添加一個 UINavigationController ,或者如果有可能的話,我已經為此做了很多研究,但我沒有發現任何有價值的東西。
在每個視圖控制器中,我想添加導航控制器
我也創建了一個,但不對所有電話負責,并且按鈕不起作用
override func viewDidLoad() {
super.viewDidLoad()
let height: CGFloat = 50
let width = self.view.frame.width
let navbar = UINavigationBar(frame: CGRect(x: 0, y: 40, width: width, height: height))
navbar.backgroundColor = UIColor.white
navbar.delegate = self
let navItem = UINavigationItem()
navItem.title = "Last Call"
navItem.rightBarButtonItem = UIBarButtonItem(title: "Add New", style: .plain, target: self, action: nil)
navbar.items = [navItem]
view.addSubview(navbar)
self.view.frame = CGRect(x: 0, y: height, width: width, height: (UIScreen.main.bounds.height - height))
}
我已經在我的視圖控制器中嵌入了一個導航控制器,這就是它的樣子 這就是它的樣子
uj5u.com熱心網友回復:
也許看看“顯示和隱藏視圖控制器”,其中解釋了一些導航概念:https ://developer.apple.com/documentation/uikit/view_controllers/showing_and_hiding_view_controllers
使用故事板時,您應該能夠使用 segue 從一個視圖控制器導航到另一個。
uj5u.com熱心網友回復:
我不完全明白你想要什么,但讓我解釋一下:
您不能
UINavigationController直接在 a 中添加 aUIViewController,我們將其包裝起來ViewController:let viewController = some ViewController //your ViewController let navigationController = UINavigationController(rootViewController: viewController)//this becomes the ViewController to be used. self.present(navigationController)//example of usage我們不包裝每個
UIViewControllerinUINavigationController,只包裝導航父母。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/497541.html
上一篇:已發布的物件未更新
