快速将视图加载到NSContainerView中 [英] Loading views into NSContainerView with swift

查看:91
本文介绍了快速将视图加载到NSContainerView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个情节提要设置,其主视图具有一堆按钮和一个容器视图,我希望每次按下这些按钮之一时都将另一个视图加载到该容器视图中,就像一个标签视图控制器可以工作,但不使用其中之一.

I have a storyboard setup with the main view having a bunch of buttons and a container view and I would like for a different view to be loaded into that container view each time I press one of those buttons, kind of like a tab view controller works but without using one of those.

此外,稍后我计划在那些视图中使用按钮来加载其他视图,以替换视图本身.

Also, later on I plan to have buttons inside those views that load other views replacing the views themselves.

任何人都可以给我一些提示吗? 谢谢

Anyone can give me some hints? Thanks

推荐答案

容器视图"定义了视图控制器的视图子图中的一个区域,该区域可以包含子视图控制器.从容器视图到子视图控制器创建一个嵌入序列在情节提要中."

"Container View defines a region within a view controller's view subgraph that can include a child view controller. Create an embed segue from the container view to the child view controller in the storyboard."

您提到了NSContainerView,所以我想您正在尝试在macOS而不是iOS上执行此操作.这是一个有用的文章和代码项目(适用于iOS 6,但我可以以此为指导在iOS 9中设置可切换子视图): http://sandmoose.com/post/35714028270/storyboards-with -custom-container-view-controllers

You mentioned NSContainerView, so I assume you're trying to do this on macOS, not iOS. Here's a useful article and code project (for iOS 6, but I was able to set up switchable subviews in iOS 9 using this as a guide): http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers

重要的部分是使用embed segue,然后通过viewDidLoad和prepareForSegue的组合将视图控制器连接在一起,然后最终从情节提要中加载其中一个可切换的视图控制器(例如每个按钮一个).他们没有连接任何其他东西.

The important bits are using the embed segue, then wiring the view controllers together through a combination of viewDidLoad and prepareForSegue, and then finally loading one of the switchable view controllers (say one for each of your buttons) from the storyboard, where they are not connected to anything else.

这篇关于快速将视图加载到NSContainerView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆