NSLog InterfaceRotation在模拟器上不起作用?

时间:2010-12-07 22:47:01

标签: iphone objective-c ios uiviewcontroller

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

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

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

1 个答案:

答案 0 :(得分:10)

您的格式说明符在哪里?

UIInterfaceOrientationtypedef 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);