1

I know there are a lot of these out there, but none of the solutions have worked for me.

Here is the situation:

AppDelegate.h

#import <UIKit/UIKit.h>
#import "SphereViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SphereViewController *sphereViewController;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.sphereViewController = [[SphereViewController alloc] initWithNibName:@"SphereViewController" bundle:nil];

    NSLog(@"%@", self.sphereViewController);

    self.window.rootViewController = self.sphereViewController;

    [self.window makeKeyAndVisible];
    return YES;
}

...

@end

When running this code the following is logged:

2014-01-04 21:21:18.691 Sphere[4978:70b] <SphereViewController: 0x10931c600>
2014-01-04 21:25:25.145 Sphere[4978:70b] Application windows are expected to have a root view controller at the end of application launch

Why am I getting the root view controller error even though I am setting it?

carloabelli
  • 4,289
  • 3
  • 43
  • 70
  • possible duplicate of [Applications are expected to have a root view controller at the end of application launch](http://stackoverflow.com/questions/7520971/applications-are-expected-to-have-a-root-view-controller-at-the-end-of-applicati) – kkocabiyik Jan 05 '14 at 02:34
  • @kkocabiyik As I have stated I have read that post and have not been successful. – carloabelli Jan 05 '14 at 02:38
  • Are you using a storyboard? To put it another way: did you start with a template that has a main.storyboard? – matt Jan 05 '14 at 02:42
  • @matt No I am using nibs (started with Empty Application) – carloabelli Jan 05 '14 at 02:43
  • The long delay is really suspicious. It should not take that long to launch your app (in fact, your app can be killed for taking this long to launch). I think you should reread the recommended linked answer and its accompanying comments. Perhaps either you are not using the app delegate you think you are, or something else is happening you aren't showing that is causing some other window, without a root view controller, to take over as the app's main window. Something is very wrong with the fundamental structure of your app project. – matt Jan 05 '14 at 02:48
  • @matt Thanks for pointing out the long delay had not noticed that before. `main.m` is calling the correct `AppDelegate`. I have no idea why something else would be taking it over (it is almost a brand new project). Also the `initWithNibName...` is default code (created by apple). What would cause this long of a delay? – carloabelli Jan 05 '14 at 02:51
  • Perhaps it is something that SphereViewController does that is the problem. – matt Jan 05 '14 at 02:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44535/discussion-between-matt-and-cabellicar123) – matt Jan 05 '14 at 02:52

1 Answers1

2

It turns out that for some reason the view property for the File's Owner in my xib was set to a GLKView which apparently causes this error.

To fix make sure your view property is linked correctly.

carloabelli
  • 4,289
  • 3
  • 43
  • 70
  • 1
    Just to clarify: It turned out that the .xib contained a normal view with a GLKView inside it. The File's Owner's `view` outlet was hooked to the GLKView. Hooking it to the superview (the normal view) instead, solved the launch problem. It is easy to hook your `view` outlet to the wrong view accidentally. I do not know why doing so caused this particular launch issue, but at least we solved it. – matt Jan 05 '14 at 03:26