1

我正在使用 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 *'
4

2 回答 2

1

设置window.rootViewController属性。

于 2012-12-27T09:07:52.610 回答
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;
}

希望它有效。

于 2012-12-27T09:12:30.033 回答