【问题标题】:Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation'从枚举类型“UIInterfaceOrientation”到不同枚举类型“UIDeviceOrientation”的隐式转换
【发布时间】:2011-12-07 10:22:04
【问题描述】:

我收到以下代码的上述编译器警告。我了解接口和设备方向之间的区别,但不确定如何修改以删除警告。有人可以帮忙吗?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (ViewController != NULL) {
    [ViewController configureForDeviceOrientation:toInterfaceOrientation];
}
if (Controller != NULL) {
    [Controller configureForDeviceOrientation:toInterfaceOrientation];
}
currentOrientation = toInterfaceOrientation;
}

【问题讨论】:

标签: iphone objective-c xcode sdk uideviceorientation


【解决方案1】:

只需投射[Controller configureForDeviceOrientation:(UIDeviceOrientation)toInterfaceOrientation];

【讨论】:

  • 谢谢 - 好主意,在这里效果很好,因为在其他地方也正确使用了相同的方法。
  • 实际上它被认为是“不好的做法”:)
  • 我尝试了与:UIDeviceOrientation orientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]; 相同的方法,但出现了新警告:Enumeration values 'UIDeviceOrientationUnknown', 'UIDeviceOrientationFaceUp', and 'UIDeviceOrientationFaceDown' not handled in switch 是否有任何转义?
  • 我认为只有一种解决方案(变通方法)才能让 switch case 来处理这 3 个接口方向。无论如何,在这种情况下,我根本不需要处理这三个。 @Ohnomycoco 这确实是一种不好的做法。这是一个死胡同,但是。
【解决方案2】:

您的方法 configureForDeviceOrientation: 期望通过 UIDeviceOrientation 枚举而不是您要传入的 UIInterfaceOrientation

如果您更正您的方法以接受来自willRotateToInterfaceOrientation: 方法的UIInterfaceOrientation,那么您将解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多