-1

For two days I am working on iOS app to fix the rotation issue, but no success. I have search everywhere in internet to find any solution, but couldn't find anything which fix my app rotation.

I have added all new function that introduced in iOS 6 for rotation to my AppDelegate class.

This is my code in AppDelegate.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
    HomeViewController *controller;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
         controller = [[HomeViewController alloc] initWithNibName: @"iPadHomePage" bundle:  nil];
    }
    else {
         controller = [[HomeViewController alloc] initWithNibName: @"HomePage" bundle: nil];
    }
    NSMutableArray *controllers = [[NSMutableArray alloc] init];
    [controllers addObject:controller];
    navController.viewControllers = controllers;
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
     return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

When I google I found out that I shouldn't use [self.window addSubview:tabBarController.view] as this will not work with iOS 6, so I replace it with [self.window setRootViewController:tabBarController] in AppDelegate class, but then I am getting an error in main class.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key labelName

What am I missing?

Nathan S.
  • 5,244
  • 3
  • 45
  • 55
informatiker
  • 2,769
  • 4
  • 17
  • 13
  • Have you searched for this error? http://stackoverflow.com/search?q=NSUnknownKeyException+setValue%3AforUndefinedKey%3A+this+class+is+not+key+value+coding-compliant+for+the+key – rmaddy Feb 28 '14 at 03:15
  • @rmaddy, yes I have, but I only get the error if I use [self.window addSubview:tabBarController.view] instead of [self.window setRootViewController:tabBarController] and I have checked my code and xib file, I haven't rename or delete any properties or any instance variable. – informatiker Feb 28 '14 at 04:25
  • But you shouldn't use the call to `addSubview` for your main view. – rmaddy Feb 28 '14 at 04:33
  • But addSubView was working so far, when I build the app long time ago with iOS 5 and I know now by release of iOS 6 I have to use [self.window setRootViewController:tabBarController] and that is what I am trying to do, which was discussed here http://stackoverflow.com/questions/13923788/ios-6-rotation-not-working, but somehow it's not working for me. I know I am missing something, but not sure what. – informatiker Feb 28 '14 at 04:38

3 Answers3

2

That crash is unrelated to rotation. It seems in your nib, you have connected an element (likely a label) to an outlet in the code that no longer exists. You likely deleted a property or an instance variable named "labelName" but forgot to remove the connection in interface builder.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • I remove all the connections, the error goes away, but when I add connection again, again the error appears. I tried to add a new textField and use the assistant editor to create the connection, then again I am getting the same error. – informatiker Feb 28 '14 at 07:59
0

this method should add to your tabbarController.m :

    - (BOOL)shouldAutorotateToInterfaceOrientation:                                (UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
         return UIInterfaceOrientationMaskAll;
    }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }

and this error"Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key labelName" ,i guess is your tabbarController.view`s xib link a nonexist IBOutlet in the tabbarcontroller.

hope this can help you

Lee xw
  • 133
  • 9
0

Finally I found the issue. Replacing the code [self.window addSubview:tabBarController.view] with [self.window setRootViewController:tabBarController] is not enough, also the order is important. I move [self.window setRootViewController:tabBarController]; [self.window makeKeyAndVisible] to the end before return YES; and now all works fine. There was no issue with connections between IBOutlet and label, .....

The correct code is:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    HomeViewController *controller;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
         controller = [[HomeViewController alloc] initWithNibName: @"iPadHomePage" bundle:  nil];
    }
    else {
         controller = [[HomeViewController alloc] initWithNibName: @"HomePage" bundle: nil];
    }
    NSMutableArray *controllers = [[NSMutableArray alloc] init];
    [controllers addObject:controller];
    navController.viewControllers = controllers;

    //this is the fix, by moving this 2 lines here
    [self.window setRootViewController:tabBarController]; 
    [self.window makeKeyAndVisible];
    return YES;
    }
informatiker
  • 2,769
  • 4
  • 17
  • 13