ios 将视图控制器从一个故事板移动或复制到另一个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13417332/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:13:47  来源:igfitidea点击:

Move or copy view controller from one storyboard to another

iosxcodeuiviewcontrollerstoryboard

提问by Vladimir Berezkin

I have several UIViewControllersin one Storyboard. Now I want to move some UIViewControllersto another Storyboard. Is it possible?

我有几个UIViewControllers故事板。现在我想将一些移动UIViewControllers到另一个故事板。是否可以?

回答by Rahul Wakade

Yes, it is possible.

对的,这是可能的。

  1. Select controllers you want to copy
  2. Press Command+ C
  3. Open your second storyboard file
  4. Press Command+ V
  1. 选择要复制的控制器
  2. Command+C
  3. 打开你的第二个故事板文件
  4. Command+V

Note:"IBOutlets remains as is after copying(Verified on Xcode 6.3.2)."

注意:“复制后 IBOutlets 保持原样(在 Xcode 6.3.2 上验证)。”

回答by AndrewK

It is possible to copy, but you have to open both storyboards at once in one project, and then copy and paste.

可以复制,但您必须在一个项目中同时打开两个故事板,然后复制和粘贴。

回答by Dark Innocence

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.

在 Xcode 8 中,如果您特别想将视图控制器移动到另一个故事板,只需通过 Cmd 选择要移动的视图控制器并单击视图控制器。保持选中状态,转到 Editor 选项卡并选择 Refactor to Storyboard。它将询问您新故事板文件的名称,然后按 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.

将创建一个新的故事板文件,其中包含您选择的视图控制器。在 Main.storyboard 中,您将看到一个 Storyboard Reference 对象代替该视图控制器,它是您对刚刚创建的新故事板的引用。

回答by Lubos Ilcik

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.

复制粘贴(Command+C、Command+V)工作正常,但请记住解决出口连接,因为 Xcode 似乎保留原始连接:关闭/重新打开项目,删除错误并重新建立丢失的连接。

回答by Marcos Reboucas

It′s possible to copy/paste but it only works if you have both Storyboards open side by side using Xcode′s Assistant Editor.

可以复制/粘贴,但只有在使用 Xcode 的助手编辑器并排打开两个 Storyboard 时才有效。

回答by nishant

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.

如果使用 Cut-n-Paste 失败,有一个解决方法。如果正在粘贴的文件中现在有 ViewController,则粘贴将失败。这使得无法选择要粘贴的情节提要。XCode 将拒绝粘贴。所以你需要先从库中拖入一个空的视图控制器到故事板中。然后在故事板中选择这个 viewController ,然后粘贴就可以了。完成粘贴后,您可以删除虚拟视图控制器。你不会再需要它了。

回答by pkamb

Interface elements can be moved between Xib and Storyboard files via Copy / Paste.

界面元素可以通过复制/粘贴在 Xib 和 Storyboard 文件之间移动。

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.

这最初对我不起作用。我试图将 UICollectionViewCell 从专用 Xib 复制到我们的主故事板。该单元格不会复制到故事板中。

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.

解决方案是在故事板中选择特定的父元素。UICollectionViewCell 可以作为故事板中 UICollectionView 的子项粘贴,否则无法粘贴。

If you're having trouble pasting a specific item, be sure to double check that you have selected a valid parent elementbefore attempting to paste.

如果您在粘贴特定项目时遇到问题,请务必在尝试粘贴之前仔细检查您是否选择了有效的父元素

回答by Konstantinos

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-24226https://www.raywenderlich.com/115697/ios-9-storyboards-tutorial-whats-new-in-storyboards

我遇到过类似的情况,在我的主故事板中,我有太多场景需要重构。我一开始的想法是标记几个并按照许多人的建议进行复制粘贴。但是,我担心故事板连接到视图控制器代码的任何分辨率。经过大量搜索,我发现自 iOS 9 以来,有一项新功能可用于“重构到 Sturuboard”。您可以在源故事板中标记多个场景,并且可以从编辑器菜单中选择该选项。然后从旧的故事板中提取所有选定的场景,创建一个新的故事板以及旧/主故事板中的链接。有用的教程是: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.

我希望这个新的官方故事板重构功能可以为此类问题提供更好的解决方案。

回答by dhaya

I think it is possible....

我认为这是可能的......

UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];

UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];

[self.navigationController pushViewController:theTabBar animated:YES];