xcode 使用界面生成器设置根控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11518638/
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
Set root controller with interface builder
提问by chwi
When I drag a Navigation Controller on to the storyboard I get the Navigation Controller and a Table View Controller. I do not want the table view, so I delete it, insert a regular view controller, change its class to e.g LoginView, right-click and drag: "Relationship Root View Controller" from the Navigation Controller on to the View Controller.
当我将导航控制器拖到情节提要上时,我会得到导航控制器和表视图控制器。我不想要表视图,所以我删除它,插入一个常规视图控制器,将其类更改为例如 LoginView,右键单击并拖动:“关系根视图控制器”从导航控制器到视图控制器。
Now when I run the application I get
现在,当我运行应用程序时,我得到
Application windows are expected to have a root view controller at the end of application launch
I do not want to fix this programatically, since last time I did this it worked out of the box (xcode 4.2, now I upgraded to 4.3). Also, when adding the Navigation Controller in 4.2 it came with a View Controller, not a Table View Controller.
我不想以编程方式修复这个问题,因为上次我这样做是开箱即用的(xcode 4.2,现在我升级到 4.3)。此外,在 4.2 中添加导航控制器时,它附带了一个视图控制器,而不是一个表视图控制器。
Navigation Controller has "Is Initial View Controller" set.
导航控制器设置了“是初始视图控制器”。
回答by flashfabrixx
Try doing it the other way around.
试着反过来做。
- Delete the navigation controller
- Select the lasting view controller, in the menu "Editor > Embed in > Navigation Controller"
- Check if the navigation controller has "Is Initial View Controller" selected
- Check if in the AppDelegate there is no unnecessary code put in the applicationDidFinish method (should be empty if you didn't put a custom code in it)
- Check if your view controller contains
-(void)loadView
and delete the method to avoid a black screen on startup
- 删除导航控制器
- 选择持久化的视图控制器,在菜单“Editor > Embed in > Navigation Controller”
- 检查导航控制器是否选择了“是初始视图控制器”
- 检查 AppDelegate 中是否有没有在 applicationDidFinish 方法中放置不必要的代码(如果您没有在其中放置自定义代码,则应为空)
- 检查您的视图控制器是否包含
-(void)loadView
并删除该方法以避免启动时出现黑屏
Hope it helps.
希望能帮助到你。
回答by 5bars
In Xcode 8:
在 Xcode 8 中:
- Right-click and drag from the Navigation Controller to the View Controller.
- Choose root view controllerin the pop-up, under the section 'Relationship Segue'.
- 右键单击并从导航控制器拖动到视图控制器。
- 在弹出窗口中,在“Relationship Segue”部分下选择根视图控制器。
回答by Cornel Damian
It's an old post, but for the ones that are still having this problem.
这是一个旧帖子,但对于那些仍然有这个问题的人。
- in xib you need a view controller and a window.
- select window and go to "Connections Inspector"
- connect rootViewController with the view controller
- 在 xib 中,您需要一个视图控制器和一个窗口。
- 选择窗口并转到“连接检查器”
- 将 rootViewController 与视图控制器连接起来
this should work, for me it worked.
这应该有效,对我来说它有效。
回答by Alexander Volkov
- Select View Controller in Interface Builder
- Open Attributes Inspector
- Set the checkbox "Initial View Controller"
- 在 Interface Builder 中选择 View Controller
- 打开属性检查器
- 设置复选框“初始视图控制器”
回答by theprojectabot
The issue is in the AppDelegate.m : - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
问题出在 AppDelegate.m 中:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Try to comment out everything except for the return of course. When making an empty application this code is inserted for you and interferes with the initial view controller check that you did with in the root view controller on your storyboard. Also within your projects target, make sure the info.plist shows your storyboard as the mainstoryboard. Then finally make sure you have your initial view controller checked within the storyboard view. Select the view controller then look at its attributes. Check that little box.
尝试注释掉除返回之外的所有内容。当创建一个空的应用程序时,此代码会为您插入并干扰您在故事板上的根视图控制器中进行的初始视图控制器检查。同样在您的项目目标中,确保 info.plist 将您的故事板显示为 mainstoryboard。然后最后确保您在故事板视图中检查了您的初始视图控制器。选择视图控制器然后查看它的属性。检查那个小盒子。
回答by chwi
My solution was to start a new project with "Single View" instead of "Empty"
我的解决方案是用“单一视图”而不是“空”开始一个新项目