“应用程序窗口应该具有根视图控制器”条件外观
我正在使用Xcode 4.5和iOS6为iPhone编写应用程序。 我也在创建一个新的UIWindow
,以便能够管理状态栏的区域(在那里显示消息等)我正在使用故事板,我的appDelegate
方法如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { return YES; }
当我将它放在名为viewDidAppear
的方法中时,该消息不会出现在控制台中:
- (void)viewDidAppear:(BOOL)animated { if (!window) { window = [[SGStatusBar alloc] initWithFrame:CGRectZero]; window.frame = [[UIApplication sharedApplication] statusBarFrame]; window.alpha = 0.5f; [self.view.window makeKeyAndVisible]; // has to be main window of app window.hidden = NO; } }
放在viewDidLoad
的相同方法在控制台中发出警告:
2012-12-27 11:34:20.838 NewApp[433:c07] Application windows are expected to have a root view controller at the end of application launch
这是因为我创建了一个新的UIWindow
吗? 为什么这两种方法之间的差异如此之大?
而且,最重要的是, 在将代码放入viewDidLoad
方法时,如何摆脱此警告?
编辑:
我在这里遇到了同样的问题,但这不是我想解决它的方式(实际上我现在正在解决它的方式)
我已经尝试通过这样做将我当前的ViewController设置为我的窗口的根视图控制器:
ViewController *vcB = [[UIViewController alloc] init]; window.rootViewController = vcB;
但我不断收到警告说:
Incompatible pointer types initializing 'ViewController *__strong' with an expression of type 'UIViewController *'
设置window.rootViewController
属性。
将以下代码添加到delegate.h和delegate.m文件中。
AppDelegate.h
@property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) YourViewController *viewController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[YourViewcontroller alloc] initWithNibName:@"YourViewcontroller" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; }
希望它有效。