0

Possible Duplicate:
XCode 4.5.1, Application windows are expected to have a root view controller at the end of application launch

I'm a total noob in IOS app developing.

I use Xcode 4.5.1 with no storyboard.

I'm upgrading an IOS 4 app because it fails to run correctly on IOS 6 devices. main view containing a question and five answers run once and stops there after user commit by pressing a button with the wanted answer, it should then reload itself with a new question and a new set of questions.

I get the infamous "Application windows are expected to have a root view controller at the end of application launch" in log output.

I've read and tried all comments and solutions in 7520971 but to no avail... still getting error and it seems to prevent me to load the view correctly.

here's what in my appDelegate.h

/*
 *  AnimViewAppDelegate.h
 *  AnimView
 *
 *  Created by Administrateur local on 11-01-19.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */


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

@interface PPScaleAppDelegate : NSObject <UIScrollViewDelegate> {
    UIWindow *window;
    RootNavigationController *RootNavigationViewController;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) RootNavigationController *RootNavigationViewController;
@end

my appDelegate.m

//
//  AnimViewAppDelegate.m
//  AnimView
//
//  Created by Administrateur local on 11-01-19.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PPScaleAppDelegate.h"
#import "QuestionView.h"

@implementation  PPScaleAppDelegate
@synthesize window;
@synthesize RootNavigationViewController;

//- (void)applicationDidFinishLaunching:(UIApplication *)application {

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //Create the main screen
    //CGRect frame = [[UIScreen mainScreen] bounds];
    //self.window = [[UIWindow alloc] initWithFrame:frame];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //2012


    //Create the main view controller
    RootNavigationViewController = [[RootNavigationController alloc] initWithNibName:NULL bundle:NULL];
    //[window addSubview:RootNavigationViewController.view];

    [self.window setRootViewController:RootNavigationViewController];

    //Show the main window
    [self.window makeKeyAndVisible];

    return YES;
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

.h

//
//  RootNavigationController.h
//  IPhonePPS
//
//  Created by Administrateur local on 11-02-11.
//  Copyright 2011 Le Groupe CDGI Inc. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "QuestionView.h"
#import "ResultView.h"
#import "ResultTableView.h"


@interface RootNavigationController : UINavigationController {

    QuestionView *QuestionViewController;
    ResultView *ResultViewController;
    ResultTableView *ResultTableViewController;

}
@property(nonatomic, assign) QuestionView *QuestionViewController;
@property(nonatomic, assign) ResultView *ResultViewController;
@property(nonatomic, assign) ResultTableView *ResultTableViewController;

-(void)switchToResultMode:(QuestionPath *)QuestionPath;
-(void)switchToResultTableMode;
-(void)switchBack:(BOOL)Reset;
@end

.m

//
//  RootNavigationController.m
//  IPhonePPS
//
//  Created by Administrateur local on 11-02-11.
//  Copyright 2011 Le Groupe CDGI Inc. All rights reserved.
//

#import "RootNavigationController.h"

@implementation RootNavigationController
@synthesize QuestionViewController, ResultViewController, ResultTableViewController;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:nibBundleOrNil {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        // Initialization code.
        QuestionViewController = [[QuestionView alloc] initWithNibName:NULL bundle:NULL];
        ResultViewController = [[ResultView alloc] initWithNibName:NULL bundle:NULL];
        ResultTableViewController = [[ResultTableView alloc] initWithNibName:NULL bundle:NULL];

        //Set the navigation bar hidden
        [self setNavigationBarHidden:YES];

        //Push the question view on the stack
        [self pushViewController:self.QuestionViewController animated:YES];

    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

-(void)switchToResultMode:(QuestionPath *)QuestionPath {
    [self pushViewController:ResultViewController animated:YES];
    [ResultViewController setQuestionPath:QuestionPath];
}

-(void)switchToResultTableMode {
    [self pushViewController:ResultTableViewController animated:YES];
}

-(void)switchBack:(BOOL)Reset{
    if(Reset){
        if([self.viewControllers count] == 3){
            [self popToRootViewControllerAnimated:YES];
        }else {
            [self popViewControllerAnimated:YES];
        }
        [QuestionViewController resetAnswers];
    }else {
        [self popViewControllerAnimated:YES];
    }
}

//-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
//  if([self visibleViewController] == self.ResultTableViewController || toInterfaceOrientation == UIInterfaceOrientationPortrait){
//      return YES;
//  }else {
//      return NO;
//  }
//}

- (BOOL) shouldAutorotate {
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

@end

spent two complete days trying to debug this but I give up and would really appreciate your help with this issue

PR

Community
  • 1
  • 1
please_reboot
  • 143
  • 10
  • please check : http://stackoverflow.com/questions/13232209/xcode-4-5-1-application-windows-are-expected-to-have-a-root-view-controller-at/13232244#13232244 – Midhun MP Nov 07 '12 at 16:44
  • Check if RootNavigationViewController is nil with the debugger, maybe there is something wrong with loading your RootNavigationController. – miho Nov 07 '12 at 16:47
  • 3
    Your variable naming scheme is rubbish. Do not (NEVER) name an instance identical to a class. Instead of ` RootNavigationViewController = [[RootNavigationController alloc] initWithNibName:NULL bundle:NULL];`, do `rootNavigationViewController = [[RootNavigationController alloc] initWithNibName:NULL bundle:NULL];` - mind that capital R. – Till Nov 07 '12 at 16:49
  • can you post at least some of your RootNavigationViewController code? it looks like it will be nil, maybe you need to use/create an init method? – ader Nov 07 '12 at 16:51
  • updated with RootNavigationController view – please_reboot Nov 07 '12 at 16:57
  • @Till I get "Use of undeclared identifier...", should I change this elsewhere ? – please_reboot Nov 07 '12 at 17:03
  • It would be better to just use [[alloc] init] if you don't have a nib. – rdelmar Nov 07 '12 at 17:29
  • if I zip my project, can someone have a quick look over it ? the complete app run except a view that load but doesn't show. must be stupid because it worked well in previous IOS. – please_reboot Nov 07 '12 at 19:22

3 Answers3

2

It would be better to just use [[alloc] init] if you don't have a nib for your navigation controller. Also, your navigation controller should be initialized with its own rootViewcontroller. I don't know which one you want to be first, but it should look something like this:

  MyFirstViewControllerClass *rootVC = [MyFirstViewControllerClass alloc] initWithNibName:@"MyFirstViewController" bundle:nil];
  RootNavigationController *nav = [[RootNavigationController alloc]initWithRootViewController:rootVC];
  self.window.rootViewController = nav;
rdelmar
  • 103,982
  • 12
  • 207
  • 218
1

You should init your RootNavigationController with a rootViewController first :

[RootNavigationController initWithRootViewcontroller:QuestionViewController];

You can find this from the UINavigationController reference :

Because the UINavigationController class inherits from the UIViewController class, navigation controllers have their own view that is accessible through the view property. When deploying a navigation interface, you must install this view as the root of whatever view hierarchy you are creating.

For instance, in -(void)switchBack:(BOOL)Reset; you popToRootViewController without even having set it.

Snaker
  • 735
  • 9
  • 20
1

You're calling [self.window setRootViewController:RootNavigationViewController]; Notice - setRootViewController. It wants a viewController. Your RootNavigationViewController is a NavigationController as referenced here @interface RootNavigationController : UINavigationController not a viewController.

It looks like you should do something like this

RootNavigationViewController = [[RootNavigationController alloc] initWithNibName:NULL bundle:NULL];
[window makeKeyAndVisible];
[window addSubview:RootNavigationViewController.view];

(referenced from Programmatically build / navigate a Navigation Controller)

I'm not sure if using

[self pushViewController:self.QuestionViewController animated:YES];

in the RootNavigationViewController is the same as doing something like this

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

But that should point you in a good direction to debug your issue.

Community
  • 1
  • 1
jer-k
  • 1,413
  • 2
  • 12
  • 23