Multiple views in Xcode storyboard view controller

2019-02-08 13:58发布

问题:

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 design of 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.).

(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.)

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.

回答1:

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.



回答2:

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

The outlet should stay connected. If you use command-x / command-v (cut/paste) you lose the outlets.

Let me know