Xcode 故事板视图控制器中的多个视图,其中之一不会出现在故事板编辑器中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13557362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple views in Xcode storyboard view controller, one of them won't appear in storyboard editor
提问by Chris Hart
I'm having trouble updating a project someone else created in Xcode. This is an app built in storyboard and in one case, there is a scene with a view controller that has multiple views underneath it in the document outline palette of the storyboard editor (shown in included image). The first view is the one that becomes highlighted in the storyboard editor when it is clicked on, and as you change the design or the objects in the view that view is updated. There is a second view (the one beneath exit and first responder) that is somehow attached to that scene but I cannot figure out how to edit the designof that view. If I click on that view or any of it's children, I can clearly see their attributes in the various inspectors on the right hand side (connections, attributes, etc.).
我在更新其他人在 Xcode 中创建的项目时遇到问题。这是一个内置故事板的应用程序,在一种情况下,在故事板编辑器的文档大纲面板中,有一个带有视图控制器的场景,该场景下有多个视图(显示在包含的图像中)。第一个视图是在单击它时在故事板编辑器中突出显示的视图,并且当您更改视图中的设计或对象时,该视图会更新。有第二个视图(出口和第一响应者下方的视图)以某种方式附加到该场景,但我不知道如何编辑该视图的设计。如果我单击该视图或其任何子视图,我可以在右侧的各种检查器中清楚地看到它们的属性(连接、属性等)。
(edit 1 - the original version of this question suggested that these additional views were used for special layouts needed when switching to landscape. They are actually used more generally than that, for example, when displaying popups over the active view.)
(编辑 1 - 这个问题的原始版本表明,这些额外的视图用于切换到横向时所需的特殊布局。它们实际上比这更普遍,例如,在活动视图上显示弹出窗口时。)
In any event, my primary interest is in being able to modify this second view. It seems like there must be a way to see it in the editor and I'm just missing it. I've searched for tutorials on implementing portrait and landscape views in storyboards (none seem to use this method), for phrases like "multiple views in storyboard scene", and looked through the menu options (including a promising option "unembed" when the second view is selected, but when clicked it removes the view from the scene and then I can't find it). I'm at a loss of where to look to learn more. How can I edit this view? Any help is appreciated.
无论如何,我的主要兴趣是能够修改第二个视图。似乎必须有一种方法可以在编辑器中看到它,而我只是想念它。我已经搜索了在故事板中实现纵向和横向视图的教程(似乎没有人使用这种方法),例如“故事板场景中的多个视图”这样的短语,并查看了菜单选项(包括一个有希望的选项“unembed”,当选择了第二个视图,但是单击它会从场景中删除视图,然后我找不到它)。我不知道去哪里了解更多信息。如何编辑此视图?任何帮助表示赞赏。
采纳答案by jhilgert00
I know it makes no sense, but you can drag it into the first view (temporarily) to edit it via the storyboard. I think this is absurd, but it does work.
我知道这没有意义,但是您可以将其拖到第一个视图中(临时)以通过故事板进行编辑。我认为这很荒谬,但确实有效。
回答by LombaX
I had this issue some times ago, and the only method I found to work graphically on the hidden view was to:
我以前遇到过这个问题,我发现在隐藏视图上以图形方式工作的唯一方法是:
- add another temporary ViewController to the Storyboard
- assign the correct class to it (MainViewController, in your case)
- delete it's main view (left menù, command + backspace)
- select the hidden view from the original ViewController and drag it in the new one, exactly under the "Main View Controller" icon (always using the left menù, the one you attached in the image)
- work on the view, add control and graphics, even connecting outlet / actions
- when finished working on the view, drag the view back to it's original position
- delete the temporary view controller
- 将另一个临时 ViewController 添加到 Storyboard
- 为其分配正确的类(MainViewController,在您的情况下)
- 删除它的主视图(左菜单,命令 + 退格键)
- 从原始 ViewController 中选择隐藏视图并将其拖动到新视图中,正好在“主视图控制器”图标下方(始终使用左侧菜单,您在图像中附加的那个)
- 在视图上工作,添加控件和图形,甚至连接插座/动作
- 完成对视图的处理后,将视图拖回其原始位置
- 删除临时视图控制器
The outlet should stay connected. If you use command-x / command-v (cut/paste) you lose the outlets.
插座应保持连接。如果您使用 command-x / command-v(剪切/粘贴),则会丢失插座。
Let me know
让我知道