I am doing a calculator for the iPhone, where on rotation of the device, a new view is displayed, and I am getting the following three errors:
CalculatorAppDelegate.m:21: warning: incompatible Objective-C types 'struct CalculatorViewController *', expected 'struct UIViewController *' when passing argument 1 of 'setRootViewController:' from distinct Objective-C type`
this error (and below) is from code:
self.window.ro开发者_运维百科otViewController = self.viewController;
CalculatorAppDelegate.m: warning: Semantic Issue: Incompatible pointer types assigning to 'UIViewController *' from 'CalculatorViewController *'
the below error is from:
UIInterfaceOrientation interfaceOrientation = [[object object] orientation];`
CalculatorViewController.m: warning: Semantic Issue: Implicit conversion from enumeration type 'UIDeviceOrientation' to different enumeration type 'UIInterfaceOrientation'
For your first 2 errors:
- Either
CalculatorViewController
is not declared as a subclass ofUIViewController
in your .h file - Or the compiler doesn't know about it, because you forgot the
#import "CalculatorViewController.h"
in your code to let the compiler know about its definition
For your last issue, this is because you misuse UIDeviceOrientation
and UIInterfaceOrientation
, which are not the same type (even quite related).
UIInterfaceOrientation
define the orientation of the user interface. It only has 4 values: Portrait, Landscape Left, Landscape Right or UpsideDown.UIDeviceOrientation
define the orientation of the device. It has 6 values, defining that your device is straight up, turns 90° left or right, upsidedown, or faceing down ou up.
If you setup your interface so that it does not rotate (shouldAutorotateToInterfaceOrientation:
returns YES only for one of the 4 UIInterfaceOrientation
), your UIDeviceOrientation
can still change (nothing prevent the user to turn his/her iPhone into any position), but your UIInterfaceOrientation
won't change.
If you setup your interface so this it does rotate (shouldAutorotateToInterfaceOrientation:
always returns YES), when the user turns his/her iPhone to the right, UIDeviceOrientation
will be UIDeviceOrientationLandscapeRight
because the iPhone will be turned right... and UIInterfaceOrientation
will be UIInterfaceOrientationLandscapeLeft
, because the interface orientation will be rotated 90° to the left, so that because the device is turned to the right, the interface will still be displayed horizontally to the user.
You can notice that UIInterfaceOrientation
and UIDeviceOrientation
have opposed values (for enums that are common to both; of course for UIDeviceOrientationFaceUp
and UIDeviceOrientationFaceDown
there is no corresponding UIInterfaceOrientation
)
精彩评论