首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xcode中UIDeviceOrientation之前的预期表达式

xcode中UIDeviceOrientation之前的预期表达式
EN

Stack Overflow用户
提问于 2010-08-29 00:45:19
回答 1查看 994关注 0票数 0

因此,我正在尝试制作一个游戏,它将根据设备在启动时的方向加载特定的XIB文件。我的代码如下所示:

代码语言:javascript
复制
- (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'“。

有没有人知道它在要求什么或者我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-29 00:49:48

UIDeviceOrientation不是一个实际的变量或常量,它是一个类型。您可能希望改用UIDevice currentDevice.orientation:

代码语言:javascript
复制
- (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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3591564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档