0

我正在为 iPhone 做一个计算器,在设备旋转时,会显示一个新视图,并且出现以下三个错误:

CalculatorAppDelegate.m:21:警告:不兼容的 Objective-C 类型'struct CalculatorViewController *',当从不同的 Objective-C 类型传递'setRootViewController:'的参数 1 时,预期的'struct UIViewController *'

此错误(及以下)来自代码:

self.window.rootViewController = self.viewController;

CalculatorAppDelegate.m:警告:语义问题:从“CalculatorViewController *”分配给“UIViewController *”的指针类型不兼容

以下错误来自:

UIInterfaceOrientation interfaceOrientation = [[object object] orientation];`

CalculatorViewController.m:警告:语义问题:从枚举类型“UIDeviceOrientation”到不同枚举类型“UIInterfaceOrientation”的隐式转换

4

1 回答 1

3

对于您的前 2 个错误:

  • 在您的.h文件CalculatorViewController中没有将其声明为的子类UIViewController
  • 或者编译器不知道它,因为你#import "CalculatorViewController.h"在代码中忘记了让编译器知道它的定义

对于您的上一个问题,这是因为您误用了UIDeviceOrientationUIInterfaceOrientation,它们不是同一类型(甚至非常相关)。

  • UIInterfaceOrientation定义用户界面的方向。它只有 4 个值:Portrait、Landscape Left、Landscape Right 或 UpsideDown。
  • UIDeviceOrientation定义设备的方向。它有 6 个值,定义您的设备是笔直向上、向左或向右旋转 90°、倒置或面朝下朝上。

如果您将界面设置为旋转(shouldAutorotateToInterfaceOrientation:仅对 4 个中的一个返回 YES UIInterfaceOrientation),您UIDeviceOrientation仍然可以更改(不会阻止用户将他/她的 iPhone 转到任何位置),但您UIInterfaceOrientation不会更改。

如果你设置你的界面让它旋转shouldAutorotateToInterfaceOrientation:总是返回是),当用户将他/她的 iPhone 向右转动时,UIDeviceOrientation将是UIDeviceOrientationLandscapeRight因为 iPhone 将向右转......并且UIInterfaceOrientation将是UIInterfaceOrientationLandscapeLeft,因为界面方向将是向左旋转 90°,这样由于设备向右转动,界面仍将水平显示给用户。

您会注意到UIInterfaceOrientation并且UIDeviceOrientation具有相反的值(对于两者共有的枚举;当然 forUIDeviceOrientationFaceUp并且UIDeviceOrientationFaceDown没有对应的UIInterfaceOrientation

于 2011-09-26T17:33:27.457 回答