我正在使用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
方法时,如何摆脱此警告?
修改
我遇到了同样的问题here,但这不是我想解决它的方式(实际上我正在解决它的方式现在)
我尝试将当前的ViewController设置为我的窗口的根视图控制器:
ViewController *vcB = [[UIViewController alloc] init];
window.rootViewController = vcB;
但我不断收到警告说:
Incompatible pointer types initializing 'ViewController *__strong' with an expression of type 'UIViewController *'
答案 0 :(得分:1)
设置window.rootViewController
属性。
答案 1 :(得分:0)
将以下代码添加到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;
}
希望它有效。