Move or copy view controller from one storyboard to another
IosXcodeUiviewcontrollerStoryboardIos Problem Overview
I have several UIViewControllers
in one Storyboard.
Now I want to move some UIViewControllers
to another Storyboard. Is it possible?
Ios Solutions
Solution 1 - Ios
Yes, it is possible.
- Select controllers you want to copy
- Press Command + C
- Open your second storyboard file
- Press Command + V
Note: "IBOutlets remains as is after copying(Verified on Xcode 6.3.2)."
Solution 2 - Ios
It is possible to copy, but you have to open both storyboards at once in one project, and then copy and paste.
Solution 3 - Ios
In Xcode 8, if specifically you want to move view controllers to another storyboard, just select the view controller(s) which you want to move by Cmd + click the view controller. Keeping them selected, Go to the Editor tab and Choose Refactor to Storyboard. It will ask you the name of the new storyboard file and press Enter.
A new storyboard file will be created with your selected view controllers in it. In the Main.storyboard, you will see a Storyboard Reference object in place of that view controller, which is your reference to the new storyboard you just made.
Solution 4 - Ios
Copy-paste (Command+C, Command+V) works fine but remember to resolve outlet connections because Xcode seems to keep the original connections: close/reopen project, delete what's wrong and reestablish missing connections.
Solution 5 - Ios
It´s possible to copy/paste but it only works if you have both Storyboards open side by side using Xcode´s Assistant Editor.
Solution 6 - Ios
If using Cut-n-Paste fails for you, there is a workaround. Paste will fail if there is now ViewController in the file that is being pasted in. That makes it impossible to select the storyboard for pasting. XCode will refuse to paste. So you need to first drag in an empty view controller into the storyboard from the library. Then select this viewController in the storyboard and then the paste will work. After you are done pasting you can delete the dummy viewController. You won't need it again.
Solution 7 - Ios
Interface elements can be moved between Xib and Storyboard files via Copy / Paste.
This was not originally working for me. I was attempting to copy a UICollectionViewCell from a dedicated Xib to our Main Storyboard. The cell would not copy into the Storyboard.
The solution was to Select the specific parent element in the storyboard. The UICollectionViewCell can be pasted in as a child of a UICollectionView in the storyboard, but otherwise cannot be pasted.
If you're having trouble pasting a specific item, be sure to double check that you have selected a valid parent element before attempting to paste.
Solution 8 - Ios
I have came up to a similar situation, where in my Main storyboard I have too many scenes and need to refactor. The idea that I had in the beginning was to mark several and do copy paste as suggested by many. However, I was concerned for any resolution of storyboard connections to the view controllers code. After much searching I found that since iOS 9 there is a new feature available to "Refactor to Storuboard". You may mark several scenes in your source storyboard and you can select from the Editor menu that option. Then all selected scenes are extracted from your old storyboard, a new storyboard is created as well as a link to that in the old/main storyboard. Useful totorials are: https://code.tutsplus.com/tutorials/ios-9-staying-organized-with-storyboard-references--cms-24226 https://www.raywenderlich.com/115697/ios-9-storyboards-tutorial-whats-new-in-storyboards
I hope that this new official storyboard refactoring functionality can provide a better solution to this kind of problems.
Solution 9 - Ios
Came to a similar situation where I needed to share one ViewController Class with 2 StoryBoard Controllers.
Apparently, the solution was simple enough:
- Split your screen between storyboard and code
- From the Storyboard select the control that is missing the connection with the class
- In the Connection Inspector, Click and Drag on the circle inside the Referencing Outlets to the code inside the Class Controller
- XCode will automatically highlight the @IBOutlet that is about to create a connection for
- as soon as you release your mouse, a connection is created between that control on the IB and in the Class
Hope this is clear enough and helpful
Solution 10 - Ios
I think it is possible....
UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];
[self.navigationController pushViewController:theTabBar animated:YES];