1

I'm writing an app for iPhone using Xcode 4.5 and iOS6. I'm also creating a new UIWindow to be able to manage the area of the status bar (to display messages there, etc.) I'm using storyboards and my appDelegate method looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

The message does not appear in the console when I put it in the method called 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;
    }  
}

The same method, put in the viewDidLoad gives a warning in the console:

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

Is this because I've created a new UIWindow? Why the difference between those two methods is so big?

And, most importantly, how can I get rid of this warning while putting the code in the viewDidLoad method?

EDIT:

I have encountered the same problem here, but it's not the way I'd like to solve it (it's actually the way I'm solving it right now)

I've tried setting my current ViewController as my window's root view controller by doing this:

ViewController *vcB = [[UIViewController alloc] init];
window.rootViewController = vcB;

But I keep getting a warning that says:

Incompatible pointer types initializing 'ViewController *__strong' with an expression of type 'UIViewController *'
Community
  • 1
  • 1
Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120
  • I think its asking you to create a NavigationController and add your first controller as root of your navigationcontroller – superGokuN Dec 27 '12 at 07:39
  • @superGokuN I believe you're wrong. Why would I need a NavigationController in an app with only 1 view? And I don't want *or* need to use one. – Sergey Grischyov Dec 27 '12 at 07:40
  • 1
    as to the difference try: http://stackoverflow.com/questions/11254697/difference-between-viewdidload-and-viewdidappear – Paxic Dec 27 '12 at 08:22

2 Answers2

1

Set window.rootViewController property .

DD_
  • 7,230
  • 11
  • 38
  • 59
Nikita P
  • 4,226
  • 5
  • 31
  • 55
  • I solved my problem by creating a new UIViewController and setting window.rootViewController property to it. Thanks for a great idea! – Sergey Grischyov Dec 27 '12 at 09:44
0

Add the following code to your delegate.h and delegate.m files.

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;
}

Hope it works.

iMash
  • 1,178
  • 1
  • 12
  • 33