简体   繁体   English

故事板中的根视图控制器

[英]Root view controller in a Storyboard

I'm playing around with a single-window template.我在玩一个单窗口模板。 I have a classic MainStoryboard.storyboard file and I have only 1 view controller (which is an Initial View Controller all by default)我有一个经典的MainStoryboard.storyboard文件,我只有 1 个视图控制器(默认情况下都是初始视图控制器

What I do is I try to implement the behaviour from this example and the Xcode tells me this:我所做的是尝试实现此示例中的行为,Xcode 告诉我:

Application windows are expected to have a root view controller at the end of application launch

I don't understand what I'm doing wrong.我不明白我做错了什么。 Here's the piece of code where I create a new UIWindow :这是我创建新UIWindow的一段代码:

UIWindow *overlayWindow = [[UIWindow alloc] init];
    overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
    overlayWindow.hidden = NO;

And of course my appDelegate starts with this:当然,我的appDelegate是这样开始的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

What am I doing wrong?我究竟做错了什么?

You should make your window key and visible by你应该让你的窗口键和可见

[overlayWindow makeKeyAndVisible];

as suggested in the very same example you linked.正如您链接的同一个示例中所建议的那样。

EDIT编辑

This the code you are using这是您正在使用的代码

UIWindow *overlayWindow = [[UIWindow alloc] init];
overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
overlayWindow.hidden = NO;

The first line its useless and potentially it is the one which is causing the warning.第一行没用,可能是导致警告的那一行。 You are creating a UIWindow instance and than throwing it away in the next line.您正在创建一个UIWindow实例,而不是在下一行中将其丢弃。

Remove it and just do:删除它并执行以下操作:

UIWindow *overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
overlayWindow.hidden = NO;

Also you should assign a root view controller to the newly created window, by您还应该为新创建的窗口分配一个根视图控制器,通过

overlayWindow.rootViewController = self.window.rootViewController;

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

相关问题 故事板:从子视图弹出到根视图控制器 - Storyboard : Pop to root view controller from subview 如何在故事板中移回根视图控制器? - How to move back to the root view controller in storyboard? 情节提要:更改情节提要中指定的UINavigation控制器的根视图 - Storyboard: Changing the Root View of a UINavigation Controller Specified in a Storyboard 如何在以编程方式使用导航控制器设置动画的情节提要中设置根视图控制器 - How to set root view controller in storyboard animated with navigation controller programmatically 故事板中的Xib视图控制器 - Xib view controller in storyboard 情节提要视图控制器未实例化? - Storyboard View Controller not instantiated? 在应用程序启动结束时的root视图控制器,默认为cocos2d viewcontroller而不是另一个Storyboard视图 - root view controller at the end of application launch, defaulting to cocos2d viewcontroller instead of another storyboard view View Controller未加载Storyboard View - View Controller not loading Storyboard View IPhone Storyboard - 分配类以在storyboard中查看控制器 - IPhone Storyboard - Assigning class to view controller in storyboard “禁用故事板后,应用程序窗口应在应用程序启动结束时具有根视图控制器” - “Application windows are expected to have a root view controller at the end of application launch” occurred after I disable storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM