2

I am getting the above compiler warning for the code below. I understand the difference between Interface and Device orientation, but am unsure how to amend to remove the warning. Can anyone help ?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (ViewController != NULL) {
    [ViewController configureForDeviceOrientation:toInterfaceOrientation];
}
if (Controller != NULL) {
    [Controller configureForDeviceOrientation:toInterfaceOrientation];
}
currentOrientation = toInterfaceOrientation;
}
GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
  • can you put method signature for **configureForDeviceOrientation** method – Rahul Sharma Dec 07 '11 at 10:24
  • See also: http://stackoverflow.com/questions/7015709/xcode-getting-warning-implicit-conversion-from-enumeration-type-uideviceorient – Brian Feb 11 '14 at 22:54

2 Answers2

6

just cast it [Controller configureForDeviceOrientation:(UIDeviceOrientation)toInterfaceOrientation];

RolandasR
  • 3,030
  • 2
  • 25
  • 26
  • Thanks - good idea and works well here as the same method is being used correctly elsewhere. – GuybrushThreepwood Dec 07 '11 at 10:41
  • 6
    actually it considered "bad practice" :) – RolandasR Dec 07 '11 at 11:07
  • I tried the same as: `UIDeviceOrientation orientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];` but a new warning: `Enumeration values 'UIDeviceOrientationUnknown', 'UIDeviceOrientationFaceUp', and 'UIDeviceOrientationFaceDown' not handled in switch` any escape? – geekay Feb 06 '12 at 17:00
  • I think there is no escape just one solution (work around) to have switch case to handle these 3 interfaceOrientations. Anyhow I don't need these three to be handled at all in this scenario. @Ohnomycoco it is indeed a bad practice. its a cul-de-sac but. – geekay Feb 06 '12 at 17:03
2

Your method configureForDeviceOrientation: is expecting to be passed a UIDeviceOrientation enum and not a UIInterfaceOrientation which you are passing in.

If you correct your method to accept a UIInterfaceOrientation from the willRotateToInterfaceOrientation: method, then you'll resolve the issue.

Luke
  • 11,426
  • 43
  • 60
  • 69