Iphone &引用;应用程序窗口应具有根视图控制器;条件外观
我正在使用Xcode 4.5和iOS6为iPhone编写一个应用程序。我还在创建一个新的Iphone &引用;应用程序窗口应具有根视图控制器;条件外观,iphone,objective-c,ios,cocoa-touch,uiwindow,Iphone,Objective C,Ios,Cocoa Touch,Uiwindow,我正在使用Xcode 4.5和iOS6为iPhone编写一个应用程序。我还在创建一个新的ui窗口,以便能够管理状态栏的区域(在那里显示消息等) 我正在使用故事板,我的appDelegate方法如下所示: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { return YES; } 当我将消息放入名为viewdide的
ui窗口
,以便能够管理状态栏的区域(在那里显示消息等)
我正在使用故事板,我的appDelegate
方法如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
当我将消息放入名为viewdide
的方法时,该消息不会出现在控制台中:
- (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
这是因为我创建了一个新的ui窗口
?为什么这两种方法之间的差异如此之大
最重要的是,在将代码放入viewDidLoad
方法时,如何消除此警告
编辑:
我也遇到过同样的问题,但这不是我想要解决的方式(实际上是我现在正在解决的方式)
我已尝试通过以下操作将当前ViewController设置为窗口的根视图控制器:
ViewController *vcB = [[UIViewController alloc] init];
window.rootViewController = vcB;
但我一直收到一条警告,上面写着:
Incompatible pointer types initializing 'ViewController *__strong' with an expression of type 'UIViewController *'
设置
window.rootViewController
属性。设置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;
}
希望它能工作。将以下代码添加到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;
}
希望它能工作。我想它要求您创建一个NavigationController,并将您的第一个控制器添加为根控制器navigationcontroller@superGokuN我相信你错了。为什么我需要在只有一个视图的应用程序中使用NavigationController?我不想也不需要使用导航控制器。至于区别,请尝试:我认为它要求您创建一个NavigationController,并将您的第一个控制器添加为navigationcontroller@superGokuN我相信你错了。为什么我需要在只有一个视图的应用程序中使用NavigationController?我不想也不需要使用故事板。至于区别,请尝试:我使用的是故事板,因此,不需要这段代码。不过,谢谢你的帮助。我使用的是故事板,因此不需要这段代码。不过,感谢您的帮助。我通过创建一个新的UIViewController并将window.rootViewController属性设置为该属性,解决了我的问题。谢谢你的好主意!我通过创建一个新的UIViewController并将window.rootViewController属性设置为该属性来解决问题。谢谢你的好主意!