55

I'm just starting my first application using storyboards. I'm using Xcode 4.5 and iOS 6 SDK. I want to know how to change the order in which the controllers are listed in the Document Outline (panel to the left of the storyboard).enter image description here

Darren
  • 10,091
  • 18
  • 65
  • 108

8 Answers8

69

In Latest Xcode 13 you can manually reorder storyboard scenes. Just drag&drop in the left pane.

Old answer

In Xcode 11 you just open storyboard XML and move specific "scene" to proper place under "scenes" tag. And that's it. The order will correspond to Document outline.

Viktor Kucera
  • 6,177
  • 4
  • 32
  • 43
  • 1
    This is exact what I want. Doing this maintains all segues/relationships. Thanks. – samthui7 Jan 11 '16 at 01:57
  • 4
    It's a really great thing to do and it works too. But those who didn't understood just right click on the main.storyboard file and open as source code. Then you would be able to see the "scenes" tag. Hope it helped to new comers. Also Thanks to @victor – Mr. JD Agrawal Dec 21 '17 at 12:20
18

In Xcode 5, the order of the view controllers/scenes listed in the storyboard's "Document Outline" seems to be determined by an alphanumeric sorting of the sceneID attribute values in the storyboard XML file.

After upgrading to Xcode 5 from 4.6 the Document Outline seemed to list my scenes in a random order. I inspected the Storyboard XML file (right click on storyboard file -> Open As -> Source Code) but the order of the scenes was correct. After further investigation I realized the sceneID attribute values were the issue. I found each sceneID attribute and added an alphanumerically increasing prefix to the value. For example, for the first scene that should appear in the Document Outline I prefixed its sceneID value with a "1a", for the second "1b", for the third "1c" and so on. After doing that for all my scenes, they had a proper listing order in the Document Outline.

I think the sceneID values are probably only used for unique identification/ordering purposes, so hopefully changing them doesn't cause other unexpected problems. But I'm still able to work with the storyboard in Interface Builder without problems and my app seems to work normally. So if this problem is irritating you as much as it did me, you might consider this workaround until Apple gives us a proper solution... just be sure to make a backup first!

Denton
  • 337
  • 3
  • 5
  • Yes Drux, the way I do it is by number first (for a particular module/tab) then subchildren as letters, i.e. 1a,1b so as you add new VC's you can still order them rather easily. You can just do odd/even numbers at first as well which leaves space for putting something in the middle as well. – Stu P. Jul 30 '14 at 20:42
  • In Xcode 6 the order of scenes correspond to Document outline. No need to change sceneID - just move the whole content under "scene" tag up or down. – Viktor Kucera Nov 08 '14 at 08:19
9

In the Document Outline, drag the orange view controller icon. As you do this you will see the blue horizontal insertion point appear between the grey boxes. Let go and the whole grey group box for the view controller will relocate.

obj-D
  • 210
  • 1
  • 4
  • 14
    This seems to copy the view controller instead of moving it. Could still be a decent solution as I can then delete the old one. Still kind of strange though. – Darren Nov 12 '12 at 13:48
  • 2
    It does copy - agreed. Didn't noticed the green plus icon and the duplicate appear. – obj-D Nov 15 '12 at 05:33
  • 4
    Pity it does not move it, since copying (and deleting the old one) removes all registered segues on the copied scene. – asgoth Jun 03 '13 at 18:37
  • 4
    Also, in Xcode 5 it seems to choose randomly where to put the copy. Dragging to a given same spot won't guarantee the copy will end up there, and undoing and redragging to the same spot yields different results. – Slipp D. Thompson Oct 09 '13 at 22:55
  • Nope. Reordering does **NOT** work. You can drag the viewController underneath all scenes to create a duplicate. Congrats, all you with duplicated viewControllers – Julian F. Weinert Jul 30 '15 at 09:46
  • @asgoth's got right. Viktor Kucera's solution does the better job. – samthui7 Jan 11 '16 at 02:00
8

At least for Xcode 4.6 , the scenes are in the order they're stored in the storyboard xml.

So you can open it with a text editor and reorder the tags to you liking, and start Xcode.

SonicBison
  • 790
  • 7
  • 21
4

I am not sure if it is still meaningfull for you. As of xcode 6.1 you can rightclick your storyboard file, choose "Open as..." -> "Source code" and change the order of view controllers rearranging sections order. I can't move them by drag'n'dropping view controller icons for unknown reason, so it is the only way that works for me.

3

For Xcode 5.1.1, you have to change the order of tag segue. Open the storyboard as source code (Right Click -> Open As -> Source code)

<segue destination="Bdn-Z8-Ql8" kind="relationship" relationship="viewControllers" id="0DS-1d-02F"/>
<segue destination="KY3-Z9-s1u" kind="relationship" relationship="viewControllers" id="u45-Ly-JkB"/>
<segue destination="k72-nP-MyV" kind="relationship" relationship="viewControllers" id="TAj-be-l8p"/>
<segue destination="gcA-x5-8Iw" kind="relationship" relationship="viewControllers" id="B7T-js-1Vs"/>

Changing the order of the above lines will change order of ViewControllers

Thai Tran
  • 9,815
  • 7
  • 43
  • 64
0

It seems that the view controllers belong to the tab bar controller, so the order of the buttons determine the order not the position of the view controllers on the screen. You should be able to drag and drop the buttons.

Cthutu
  • 8,713
  • 7
  • 33
  • 49
  • I'm not sure if I understand your answer. My app works fine, and tapping the tab bar loads the correct view controllers. I'm just wondering if there is a way to change the order in which they are listed on the left. You see they are ordered: FirstViewController, FourthViewController, ThirdViewController, SecondViewController. I can't seem to drag the view controllers in the list on the left around. – Darren Sep 25 '12 at 16:07
  • Cthutu is correct - click once on the tab bar your storyboard to select it (maybe twice?) then drag the buttons into the desired order. – Joshua Nozzi Sep 25 '12 at 17:05
  • I know how to order the buttons in the tab bar. What I want to know is how to change the order that the view controllers are listed in the panel on the left. – Darren Sep 25 '12 at 19:52
  • 1
    Ah. I don't think that's possible right now. Managing the order of user-created elements in a nib/xib was doable in Interface Builder 3 and lower, but 4 is still very much a new rewrite. Lots of interactions we're used to having aren't yet supported. – Joshua Nozzi Oct 03 '12 at 13:13
0

Just Drag and Drop the icon on the bottom in your first View Controller Screen. Xcode 11.6

Jean Luiz
  • 20
  • 2