views:

22

answers:

1

So i am trying to make a game that will load a specific XIB file according to the device's orientation at launch. my code looks like this:

- (id)initWithNibName:(NSString *)nibName owner:owner bundle:(NSBundle *)bundleName {
    if (UIDeviceOrientation == UIDeviceOrientationLandscapeLeft || UIDeviceOrientation == UIDeviceOrientationLandscapeRight) {
        [[NSBundle mainBundle] loadNibNamed:@"Landscape.xib" owner:self options:nil];
    }
    if (UIDeviceOrientation == UIDeviceOrientationPortrait || UIDeviceOrientation == UIDeviceOrientationPortraitUpsideDown) {
        [[NSBundle mainBundle] loadNibNamed:@"Portrait.xib" owner:self options:nil];
    }

    return self;
}

and i get this error: on both occurrences of UIDeviceOrientation: "error: expected expression before 'UIDeviceOrientation'".

Does anyone know what it is asking for or what i'm doing wrong?

+1  A: 

UIDeviceOrientation is not an actual variable or constant, it's a type. You might want to use [UIDevice currentDevice].orientation instead:

- (id)initWithNibName:(NSString *)nibName owner:owner bundle:(NSBundle *)bundleName {
    UIDeviceOrientation   orientation = [UIDevice currentDevice].orientation;
    NSString   *nibName = UIDeviceOrientationIsLandscape(orientation) ? @"Landscape" : @"Portrait";

    [[NSBundle mainBundle] loadNibNamed:@nibName owner:self options:nil];

    return self;
}
Ben Gottlieb