Subclassed UIViewController returns: 'applications are expected...'

Discussion in 'iOS Programming' started by NickFalk, Feb 2, 2012.

  1. NickFalk macrumors 6502


    Jun 9, 2004
    It's been a while since I've used UIKit to any extent (been enjoying cocos2d for my game stuff). It seemed to flow really easy though when I went back, right up until the moment I decided to make an app that was not set up with a xib-containing template.

    Upon running it in the simulator I received the following message: "applications are expected to have a root view controller at the end of application launch."

    Which sounds sensible. However what I can't break my head around is why it my subclassed UIViewController won't be accepted as a view controller..

    I have a subclassed UIViewController class called MasterController. It has the following init method:

    -(id) init
    	self	=	[super init];
    	if (self) {
    		NSLog(@"%@ MasterController init", self);
    		[self loadView];
    		return self;
    		return nil;
    I've added the following property to my AppDelegate:
    @property (nonatomic, retain) MasterController *masterController;
    It should all come together in the application: didFinishLaunchingWithOptions: method
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    	NSLog(@"%@ AppDelegate application", self);
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        self.window.backgroundColor = [UIColor blackColor];	
    	self.masterController		= [[[MasterController alloc] init]autorelease];
    	self.window.rootViewController	= self.masterController;
    	[[self window] makeKeyAndVisible];
    	return YES;
    The above mentioned message is returned though.
    If I replace my own class with a standard UIViewController the message is not returned so it seems obvious that my subclass is not accepted for some reason...
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Must be something in the code / settings we're not seeing because I tried the same thing as above in a test project and it worked fine: no "applications are expected..." message.

Share This Page