如何在uiviewController中创建一个uinavigation controll,以程序为快速
我是在Swift故事板中为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))
}
我在视图控制器中嵌入了导航控制器,这就是它的外观 这就是它的外观
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许请查看“显示和隐藏视图控制器”,其中解释了某些导航概念:
使用故事板时,您应该能够使用SEGUE从一个视图控制器导航到另一个视图控制器。
Maybe have a look at "Showing and Hiding View Controllers" where some navigation concepts are explained: https://developer.apple.com/documentation/uikit/view_controllers/showing_and_hiding_view_controllers
When using storyboards you should be able to use a segue to navigate from one view controller to another.
我不完全理解您想要的东西,但让我解释一些事情:
您不能直接在
uinavigationController
中直接添加uiviewController
,我们将ViewController
而不是:我们不包装所有<代码> uiviewController 在
uinavigationController
,只有导航父母。I don't fully understand what you want, but let me explain a few things:
You can't add a
UINavigationController
directly in aUIViewController
, we wrap theViewController
instead:We don't wrap every
UIViewController
inUINavigationController
, only the navigation parents.