不使用标准Apple导航栏(Swift)的导航结构

时间:2014-11-18 16:31:52

标签: ios swift navigation interface-builder

是否可以使用Interface Builder设置导航结构,而无需使用标准Apple导航栏?我想将打开新视图控制器的操作应用到我自己的自定义按钮。

这是不可能的,你们有没有一个好地方可以在不使用界面构建器的情况下开始学习这个?

2 个答案:

答案 0 :(得分:1)

在IB中,您可以将导航栏的类更改为您自己的类。

enter image description here

如果您不使用IB,可以使用[[UINavigationController alloc] initWithNavigationBarClass:[MyNavBar class] toolbarClass:nil]

答案 1 :(得分:1)

您必须使用根视图控制器嵌入导航控制器。为此选择故事板中的视图控制器,单击编辑器 - >嵌入在> navigationController。

在viewDidload中写  self.navigationController?.navigationBar.hidden = true

在顶部有一个大小为导航栏的标签,在其上添加一个按钮,并在其操作方法中写下以下代码

@IBAction func goToNextController(sender: AnyObject)
    {
        let second = self.storyboard?.instantiateViewControllerWithIdentifier("second") as SecondViewController

        self.navigationController?.pushViewController(second, animated: true)
    }

这里secondViewController是我们推送的那个

同样在secondViewcontroller的顶部有一个标签和按钮,并在你的按钮的动作方法中写下下面的代码

![@IBAction func previousButtonTapped(sender: AnyObject)
    {
        self.navigationController?.popViewControllerAnimated(true)
    }][2]
相关问题