如何在uiviewController中创建一个uinavigation controll,以程序为快速

发布于 2025-02-11 15:07:37 字数 1071 浏览 1 评论 0 原文

我是在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))

}

我在视图控制器中嵌入了导航控制器,这就是它的外观 这就是它的外观

I´m creating a multiScene app for iOS in Swift Storyboard.
I want to add a UINavigationController programmatically in UIViewController or if there is possible with storyboard, I have made a lot a research for this and I haven´t find anything valuable.

In each view controller I want to add the Navigation Controller

Also I have create one but is not responsible for all phones and the button does not work

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))

}

I have embed a Navigation controller in my view controller and this is how it looks like
This is how it looks like

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫以 2025-02-18 15:07:37

也许请查看“显示和隐藏视图控制器”,其中解释了某些导航概念:

使用故事板时,您应该能够使用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.

微凉 2025-02-18 15:07:37

我不完全理解您想要的东西,但让我解释一些事情:

  1. 您不能直接在 uinavigationController 中直接添加 uiviewController ,我们将 ViewController 而不是:

     让ViewController =某些ViewController //您的ViewController
    让NavigationController = uinavigationController(rootviewController:viewController)//这成为要使用的ViewController。 
    self.present(navigation controller)//使用示例
     
  2. 我们不包装所有<代码> uiviewController 在 uinavigationController ,只有导航父母。

I don't fully understand what you want, but let me explain a few things:

  1. You can't add a UINavigationController directly in a UIViewController, we wrap the ViewController instead:

    let viewController = some ViewController //your ViewController
    let navigationController = UINavigationController(rootViewController: viewController)//this becomes the ViewController to be used. 
    self.present(navigationController)//example of usage
    
  2. We don't wrap every UIViewController in UINavigationController, only the navigation parents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文