因此,我正在尝试制作一个游戏,它将根据设备在启动时的方向加载特定的XIB文件。我的代码如下所示:
- (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;
}我得到了这个错误:在两次出现错误时:"error: expected before 'UIDeviceOrientation'“。
有没有人知道它在要求什么或者我做错了什么?
发布于 2010-08-29 00:49:48
UIDeviceOrientation不是一个实际的变量或常量,它是一个类型。您可能希望改用UIDevice currentDevice.orientation:
- (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;
}https://stackoverflow.com/questions/3591564
复制相似问题