简体   繁体   English

跨多个故事板的导航栏

[英]Navigation Bar Across Multiple Storyboards

I've separated my views into multiple storyboards to make managing the project as a team much easier.我已将我的视图分成多个故事板,以便更轻松地作为一个团队管理项目。 The only problem is that I want to have the navigation bar across all of my different view controllers.唯一的问题是我希望在所有不同的视图控制器中都有导航栏。 I embedded the first view controller in a navigation controller which added the navigation bar.我将第一个视图控制器嵌入到添加了导航栏的导航控制器中。 In my second storyboard, I wanted to constrain a view to the navigation bar, however, since this view controller isn't embedded in a navigation controller, there isn't anything to constrain the view to.在我的第二个故事板中,我想将视图约束到导航栏,但是,由于此视图控制器未嵌入到导航控制器中,因此没有任何可以约束视图的内容。 I put a navigation bar without a navigation controller to constrain to, however, when I perform the segue from the first storyboard, this results in two navigation bars.我放置了一个没有导航控制器的导航栏来限制,但是,当我从第一个故事板执行 segue 时,这会导致两个导航栏。 How do I make this so that I can constrain the view to the navigation bar without having two of them?我如何做到这一点,以便我可以将视图限制在导航栏上而没有两个? Thanks in advance!提前致谢!

I'm not sure your problem.我不确定你的问题。 I guess that you want to use ONE navigation bar to constrain many UIViewController in different Storyboard.我猜您想使用一个导航栏来约束不同 Storyboard 中的许多 UIViewController。 Here is my answer.这是我的答案。

Step 1: Set up Storyboard ID in each UIViewController第 1 步:在每个 UIViewController 中设置 Storyboard ID

故事板 ID

Step 2: push new UIViewController第二步:推送新的 UIViewController

func switchNextView() {
    let storyboardName:String = "xxxxxx"
    let storyboardId:String = "xxxxx"

    let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
    let vc: UIViewController = 
        storyboard.instantiateViewController(withIdentifier: storyboardId) as! 
        UIViewController
    self.navigationController?.pushViewController(vc, animated: true)
}

You can go from on view controller to another by three way:-您可以通过三种方式从一个视图控制器转到另一个视图控制器:-

First using segue as you are already doing首先使用 segue,因为你已经在做

second You can Present your view controller by第二,您可以通过以下方式展示您的视图控制器

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil) 

Third You can Navigate View controller by第三,您可以通过以下方式导航视图控制器

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
    self.navigationController?.pushViewController(controller, animated: true) 

thanks for helping me out. 谢谢你的协助。 As mentioned in the comment by @Paulw11 the following worked 如@ Paulw11的评论中所述,以下工作有效

"Just constrain to the top layout guide. This will respect the navigation bar at runtime if it is present." “仅限于顶部布局指南。这将在运行时遵守导航栏(如果存在的话)。”

Thanks again for the help! 再次感谢您的帮助! Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM