Can anyone tell me what is wrong with this code? I’m trying to determine what orientation (portrait or landscape, the device is in). Thanks.
- (void)checkOrientation
{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
switch (orientation)
{
case UIInterfaceOrientationPortrait:
self.tableView.backgroundColor = [UIColor whiteColor];
break;
case UIInterfaceOrientationPortraitUpsideDown:
self.tableView.backgroundColor = [UIColor whiteColor];
break;
case UIInterfaceOrientationLandscapeLeft:
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background2.png"]];
break;
case UIInterfaceOrientationLandscapeRight:
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background2.png"]];
break;
}
[self.tableView reloadData];
}
Warning
Implicit conversion from enumoration type ‘UIDeviceOrientation’ to differnt enumeration type ‘UIInterfaceOrientation
Now that you’ve posted the error, the problem is clear. This line:
returns an instance of
UIDeviceOrientation, not an instance ofUIInterfaceOrientation. To remove the warning and correct the code, you can change the offending line to this: