【问题标题】:Add a navigation bar to a view in code, without a navigation controller在代码中向视图添加导航栏,无需导航控制器
【发布时间】:2015-06-15 10:56:42
【问题描述】:

我在 Swift 中的导航栏有问题。我像这样从一个视图控制器移动到另一个视图控制器:

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameViewController") as GameViewController
nextViewController.transitioningDelegate = self.transitionManager
self.presentViewController(nextViewController, animated:true, completion:nil)

但是当我看到我的第二个视图控制器时,它就消失了。我不能在这里使用 segue。

如何在 Swift 中添加一个导航栏,带有一个栏按钮项,而没有导航控制器?

我看到了这个:Add a navigation bar to a view without a navigation controller

【问题讨论】:

    标签: ios swift cocoa-touch uinavigationcontroller uinavigationbar


    【解决方案1】:

    为此,您可以使用 IB:将 Navigation Bar 从左侧窗格拖到您的 UIViewController 上。如图所示:

    要根据设备正确设置Navigation Bar 的大小,您需要添加约束以将顶部边缘固定到视图的顶部,并将左右边缘固定到视图的左右(高度是内在的,不需要约束)。这也可以在 IB 中完成:

    完成这两个步骤后,您可以像往常一样使用Navigation Bar - 例如,我在第一张图片中的Navigation Bar 中添加了Bar Button Item

    【讨论】:

    • 感谢这个答案,但我会澄清。我想要它在代码中
    猜你喜欢
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    相关资源
    最近更新 更多