简体   繁体   English

iOS / Storboard:使用自动布局在一个Storyboard中复制和粘贴View Controller是否安全?

[英]IOS/Storboard: Is it Safe to Copy and Paste View Controller within One Storyboard with Autolayout

I have a view controller in storyboard with a lot of elements and autlayout constraints that also has segues from another VC and I need to make a similar VC. 我在情节提要中有一个视图控制器,其中包含很多元素和自动布局约束,这些视图也与另一个VC有关联,因此我需要制作一个类似的VC。

Is it safe to copy and paste a VC to create a duplicate? 复制并粘贴VC创建副本是否安全? I would cut and past from the navigator pane, not the actual storyboard. 我会从导航器窗格(而不是实际的故事板)剪切过去。

The VC in question is wired to a class. 有问题的VC连接到一个类。 The cloned VC will get its own class and I don't mind deleting the connections. 克隆的VC将获得自己的类,并且我不介意删除连接。 I just don't want to mess up storyboard. 我只是不想弄乱故事板。

When I was first experimenting with Storyboard, I tried this a couple times and it seemed to corrupt early projects so I'm wary. 当我第一次尝试使用Storyboard时,我尝试了几次,它似乎破坏了早期的项目,因此我很警惕。 Are there any safeguards that should be taken first? 是否应首先采取任何保护措施?

Thanks in advance for any guidance or suggestions. 在此先感谢您的指导或建议。

Short answer is YES from the navigator pane or the canvas and Autolayout constraints will be preserved in your cloned VC. 简短的答案是在导航器窗格中为“是”,否则画布和“自动布局”约束将保留在克隆的VC中。

When you select your cloned VC in Interface Builder, you can edit it's custom class in the Identity inspector. 当您在Interface Builder中选择克隆的VC时,可以在身份检查器中编辑它的自定义类。

If your cloned VC as a different class, you should definitely clean up the outlet connections and the IBActions. 如果您克隆的VC是不同的类,则一定要清理出口连接和IBAction。

It's totally feasible to copy ViewController. 复制ViewController是完全可行的。 Actually instead of copying VC, you are copying and paste scene. 实际上,您是在复制并粘贴场景,而不是复制VC。

In the following , I paster a bunch of tableviewController scene from the top scene. 接下来,我从顶部场景粘贴一堆tableviewController场景。 在此处输入图片说明

After copy/paste, the new scenes are completely independent of each other even with the original tableviewController scene. 复制/粘贴后,即使使用原始tableviewController场景,新场景也彼此完全独立。

If you need to change to other customized vc, just change the name here. 如果需要更改为其他自定义的vc,只需在此处更改名称。 Now the new scene is configured to your own new vc class and again has nothing to do with the original vc. 现在,新场景已配置为您自己的新vc类,并且与原始vc无关。

在此处输入图片说明

One thing needs to remember: if your original vc has storyboard identifier, you may need to change after copy/paste. 需要记住一件事:如果原始的vc具有情节提要标识符,则可能需要在复制/粘贴后进行更改。

If you have too many identifies, you may consider to paste the scene to another storyboard. 如果标识太多,则可以考虑将场景粘贴到另一个故事板上。 Then you can use an reference storyboard to help you connect. 然后,您可以使用参考情节提要来帮助您建立联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在情节提要中将项目从一个视图复制并粘贴到另一个视图而无需引用出口? - Copy & Paste items from one view to another within storyboard without referencing outlets? 在StoryBoard中为单个View Controller禁用自动布局 - Disabling AutoLayout for a single View Controller in storyBoard 将视图控制器从一个故事板移动或复制到另一个 - Move or copy view controller from one storyboard to another iOS-推送到故事板中没有的View Controller - iOS - Pushing to a View Controller that is not in the Storyboard iOS - 以编程方式添加新视图以使用我的storyboard autolayout viewcontroller - iOS - Programatically add a new view to work with my storyboard autolayout viewcontroller 使用Storyboard或xib中的iOS AutoLayout和SizeClass在不同屏幕中可变的视图高度 - Variable height of view in different screens with iOS AutoLayout And SizeClass in Storyboard or xib iOS /自动布局/故事板:引脚视图对表头无响应 - iOS/autolayout/storyboard: Pin view not responsive for table header 将故事板控制器复制并粘贴到xib文件中。 支持与否? - Copy and paste storyboard controller into xib file. Supported or not? Storboard的iOS RESideMenu使用 - iOS RESideMenu usage with Storboard iOS故事板AutoLayout并添加约束 - iOS storyboard AutoLayout and adding constraint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM