简体   繁体   English

如何使用Interface Builder和Swift在xCode6中正确创建故事板

[英]How to properly create a storyboard in xCode6 using Interface Builder and Swift

I need help using Interface builder to create a storyboard and initial view, using xCode 6 and Swift. 我需要使用“界面”构建器来帮助创建故事板和初始视图,使用xCode 6和Swift。 I do not want to start with the template "Single View Application" but with an "Empty Application" - for learning purposes. 我不想从模板“单视图应用程序”开始,而是使用“空应用程序” - 用于学习目的。

I am starting with File->New->Application in xCode 6. In the left pane I have selected iOS-> Application and I am choosing the template "Empty Application" 我从xCode 6中的File-> New-> Application开始。在左侧窗格中我选择了iOS-> Application,我选择了模板“Empty Application”

So now, I have my empty application and I want to use Interface Builder to create a story board. 所以现在,我有我的空应用程序,我想使用Interface Builder来创建一个故事板。

I select File-New-File - then in the left pane I select iOS-User Interface and in the right pane I select Storyboard. 我选择File-New-File - 然后在左侧窗格中选择iOS-User Interface,在右侧窗格中我选择Storyboard。 I call my storyboard "Main" 我称我的故事板为“主要”

That seems to do nothing, so then upon examining other templates, I decided that I need to go to info.plist and add a key/value pair, and so in info.plist I added a key "Main storyboard file base name" and a value of "Main" 这似乎什么都不做,所以在检查其他模板时,我决定我需要去info.plist并添加一个键/值对,所以在info.plist中我添加了一个键“主故事板文件基本名称”和值“主”

After that I get the error: 之后我得到错误:

Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? 无法为UIMainStoryboardFile'Main'实例化默认视图控制器 - 可能未设置指定的入口点?

So now I go to the story board and drag and drop a "View Controller" onto the storyboard, and btw - in the View controller inspector it is checked "initial scene - Is Initial View Controller" 所以现在我转到故事板并将“视图控制器”拖放到故事板上,顺便说一句 - 在View控制器检查器中,它被检查“初始场景 - 是初始视图控制器”

But this doesn't create any swift file - which may be expected, but just to be clear it doesn't. 但这并没有创建任何swift文件 - 这可能是预期的,但只是要明确它不会。 Now when I try to run, I get the error: 现在,当我尝试运行时,我收到错误:

Application windows are expected to have a root view controller at the end of application launch 应用程序窗口应在应用程序启动结束时具有根视图控制器

So any ideas? 那么任何想法? I am trying to figure out how you properly use Interface Builder to create a storyboard and initial view and do a basic hello world, without skipping past the use of the tool to have it created for me in a template, because my assumption is you will quickly have more complex apps than can be created from a template, and it might be good to know how to use the tools - but I am not finding documentation on the subject. 我试图找出你如何正确使用Interface Builder创建一个故事板和初始视图并做一个基本的hello世界,而没有跳过使用该工具在模板中为我创建它,因为我的假设是你会快速拥有比从模板创建的更复杂的应用程序,知道如何使用这些工具可能会很好 - 但我没有找到有关该主题的文档。

Edit: strange timing I happened to find the answer just as someone else had also correctly answered the issue for me, so I will edit this post and remove the answer - as the answer below is exactly correct. 编辑:奇怪的时间我碰巧找到答案就像其他人也正确地为我解答了问题,所以我将编辑这篇文章并删除答案 - 因为下面的答案是完全正确的。

The storyboard automatically creates the window and instantiates the initial view controller for you. 故事板自动创建窗口并为您实例化初始视图控制器。 The code in the app delegate is creating another window which you don't want. app delegate中的代码正在创建另一个您不想要的窗口。 You should delete all the code in didFinishLaunchingWithOptions, except for "return true". 您应该删除didFinishLaunchingWithOptions中的所有代码,“return true”除外。 It will then run properly. 然后它将正常运行。

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

相关问题 如何使用Storyboard在Xcode6中创建UIButton连接? - How to create UIButton connections in Xcode6 using Storyboard? XCode6 Interface Builder iPad问题 - XCode6 Interface Builder iPad issues swift-如何在不使用XCode接口构建器的情况下将UI连接到代码? - swift - how to connect UI to code without using XCode interface builder? UITableViewCell在使用xcode6 beta6接口构建器的iOS7和iOS8模拟器中表现不同 - UITableViewCell behave differently in iOS7 and iOS8 simulator using xcode6 beta6 interface builder 如何在情节提要XCode6(Swift)中将所有ViewController设置为横向 - How can I set all viewcontroller as a landscape in storyboard XCode6 (Swift) Xcode6 Interface Builder已经“隐藏”了我的观点? - Xcode6 Interface Builder has “hidden” my views? 如何在xcode 6.3界面构建器情节提要中默认模拟指标? - How to default simulated metrics in xcode 6.3 interface builder storyboard? 在Interface Builder故事板上创建UIView - Create UIView in Interface Builder Storyboard 使用Autolayout Xcode6将UILabel相对于Universal Storyboard中的UIImage定位 - Position UILabel relative to UIImage in Universal Storyboard using Autolayout Xcode6 使用情节提要xcode6在视图控制器之间传递数据 - pass data between view controller using storyboard xcode6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM