0

デバイスの回転時に新しいビューが表示される iPhone 用の電卓を実行していますが、次の 3 つのエラーが発生しています。

CalculatorAppDelegate.m:21: 警告: 互換性のない Objective-C の型 'struct CalculatorViewController *'、予期される 'struct UIViewController *' は、異なる Objective-C の型から 'setRootViewController:' の引数 1 を渡すときに'

このエラー(および以下)はコードからのものです:

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"または、コンパイラにその定義を知らせるためにコード内でを忘れたため、コンパイラはそれを知りません

あなたの最後の問題では、これは、同じタイプではない (まったく関連していない)UIDeviceOrientationとを誤用したためです。UIInterfaceOrientation

  • UIInterfaceOrientationユーザー インターフェイスの方向を定義します。値は 4 つだけです: Portrait、Landscape Left、Landscape Right、または UpsideDown。
  • UIDeviceOrientationデバイスの向きを定義します。これには 6 つの値があり、デバイスが真上、左右に 90° 回転、逆さま、または下向きまたは上向きであることを定義します。

インターフェイスが回転しないshouldAutorotateToInterfaceOrientation:ように設定した場合 ( 4 つのうちの 1 つに対してのみ YES を返すUIInterfaceOrientation)、UIDeviceOrientation変更することはできます (ユーザーが iPhone を任意の位置に回すことを妨げるものは何もありません) が、UIInterfaceOrientation変更されません。

これが回転するようにインターフェースをセットアップした場合(shouldAutorotateToInterfaceOrientation:常に YES を返す)、ユーザーが iPhone を右に回すと、iPhone が右に回転UIDeviceOrientationするUIDeviceOrientationLandscapeRightUIInterfaceOrientationためUIInterfaceOrientationLandscapeLeftです...そして、インターフェースの向きが左に 90° 回転したため、デバイスが右を向いているため、インターフェイスはユーザーに対して水平に表示されます。

UIInterfaceOrientationとが反対の値UIDeviceOrientationを持っていることに気付くことができます(両方に共通する列挙型の場合、もちろんとには対応するものはありません)UIDeviceOrientationFaceUpUIDeviceOrientationFaceDownUIInterfaceOrientation

于 2011-09-26T17:33:27.457 に答える