简体   繁体   English

在 Xcode 中创建一个新的故事板并使其成为主要的故事板(模拟器中的黑屏)

[英]Creating a new storyboard in Xcode and making it the main one (black screen in simulator)

I accidentally deleted my original Main.storyboard file that came with the project when I first began it.我第一次开始时不小心删除了项目附带的原始 Main.storyboard 文件。 Now, I need all of the steps necessary to create a new storyboard and make it the new main storyboard for the project.现在,我需要所有必要的步骤来创建一个新的故事板并使其成为项目的新主故事板。 I only need one storyboard.我只需要一个故事板。 When I run my app in simulator my whole app is just a black screen.当我在模拟器中运行我的应用程序时,我的整个应用程序只是一个黑屏。 Any help would be greatly appreciated.任何帮助将不胜感激。 I am programming in Swift.我正在用 Swift 编程。

You need to make the following things to get it to work:您需要进行以下操作才能使其正常工作:

1. Create a new file 1.新建一个文件

添加文件


2. Select, name and save the Storyboard file 2.选择、命名并保存 Storyboard 文件

故事板


3. Select the file in the Deployment Info 3.Deployment Info中选择文件

部署信息


4. Drag a view controller into the file and select it as initial view controller (look at the inspector on the right) 4.将一个视图控制器拖入文件并选择它作为初始视图控制器(查看右侧的检查器)

视图控制器

Let Me come up with a better solution让我想出一个更好的解决方案

Method 1方法一

if you have deleted the story board as remove refrence like this如果你已经删除了故事板,像这样删除引用

在此处输入图片说明

don't worry about anything your storyboard is still safe.不要担心你的故事板仍然安全。

inside your project suppose you have your project saved on desktop as project1 go to project1 then you'll see a couple of folders find a folder named project1在您的项目中,假设您将项目保存在桌面上,作为 project1 转到 project1 然后您会看到几个文件夹找到一个名为project1的文件夹

Open it and you'll see some file's like this打开它,你会看到一些这样的文件

在此处输入图片说明

all you have to do is go to Base.ipoj folder and if you find these files您所要做的就是转到 Base.ipoj 文件夹,如果您找到这些文件

在此处输入图片说明

either you can drag the file to your project or you can add them by this way.您可以将文件拖到您的项目中,也可以通过这种方式添加它们。

在此处输入图片说明

browse your file For example desktop/project1/project1/Base.Iproj/Main.Storyboard浏览您的文件例如 desktop/project1/project1/Base.Iproj/Main.Storyboard

在此处输入图片说明

click on Add button and you'll have your Storyboard file.单击“添加”按钮,您将拥有 Storyboard 文件。

and if you deleted the file by selecting "Move to trash" You can look up into trash copy your file to another folder and add the file as mentioned in the above steps.如果您通过选择“移至垃圾箱”删除了文件,您可以查看垃圾箱,将您的文件复制到另一个文件夹,然后按照上述步骤添加该文件。

Method 2方法二

if you want to add a new Storyboard just do :-如果您想添加一个新的故事板,请执行以下操作:-

在此处输入图片说明

在此处输入图片说明

click on Next and save it and You'll have your new Storyboard.单击 Next 并保存它,您将拥有新的 Storyboard。

添加新的故事板(新文件..用户界面),然后转到项目的目标,然后在(主界面)字段中添加您的故事板名称。

I Also noticed that you have asked about assign the storyboard's view controller as the main one :-我还注意到您询问了将故事板的视图控制器分配为主要控制器的问题:-

here's the way :-这是方法:-

在此处输入图片说明

Click on View Controller单击视图控制器

在此处输入图片说明

Open Attribute Inspector打开属性检查器

在此处输入图片说明

Select View Controller as the initial one and you're ready to go.选择 View Controller 作为初始控制器,您就可以开始了。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM