【问题标题】:NSLog InterfaceRotation doesn't work on simulator?NSLog InterfaceRotation 在模拟器上不起作用?
【发布时间】:2010-12-07 22:47:01
【问题描述】:

我想通过在我的 UIViewController 中跟踪该代码来了解为什么在 iOS 模拟器上测试时没有控制台输出 - 它仅通过在设备上进行测试来跟踪。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    NSLog(@"willRotateToInterfaceOrientation: ", toInterfaceOrientation);
}

我如何打印出 UIInterfaceOrientation 值(枚举类型)? 很高兴得到您的帮助..谢谢

【问题讨论】:

    标签: iphone objective-c ios uiviewcontroller


    【解决方案1】:

    您的格式说明符在哪里?

    UIInterfaceOrientation 是一个typedef enum,不是一个对象,所以你不能使用%@ 作为格式说明符。

    应该是这样的:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
       NSLog(@"willRotateToInterfaceOrientation: %d", toInterfaceOrientation);
    }
    

    如果您真的需要这种“漂亮打印”功能,您可以通过switch 运行它,如下所示:

    NSString *orient;
    switch(toInterfaceOrientation) {
       case UIInterfaceOrientationLandscapeRight:
           orient = @"UIInterfaceOrientationLandscapeRight";
           break;
       case UIInterfaceOrientationLandscapeLeft:
           orient = @"UIInterfaceOrientationLandscapeLeft";
           break;
       case UIInterfaceOrientationPortrait:
           orient = @"UIInterfaceOrientationPortrait";
           break;
       case UIInterfaceOrientationPortraitUpsideDown:
           orient = @"UIInterfaceOrientationPortraitUpsideDown";
           break;
       default: 
           orient = @"Invalid orientation";
    }
    NSLog(@"willRotateToInterfaceOrientation: %@", orient);
    

    【讨论】:

    • 是的,感谢您的快速回答!我如何打印出 UIInterfaceOrientation-value?
    • 代码就是这样做的。它是一个数值 - 您需要查询文档以获取翻译。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    相关资源
    最近更新 更多