gpt4 book ai didi

ios - 警告 : passing incompatible type to setRootViewController:

转载 作者:行者123 更新时间:2023-11-28 20:43:08 27 4
gpt4 key购买 nike

我正在为 iPhone 做一个计算器,当设备旋转时,会显示一个新 View ,但我收到以下三个错误:

CalculatorAppDelegate.m:21: warning: incompatible Objective-C types 'struct CalculatorViewController *', expected 'struct UIViewController *' when passing argument 1 of 'setRootViewController:' from distinct Objective-C type`

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

self.window.rootViewController = self.viewController;

CalculatorAppDelegate.m: warning: Semantic Issue: Incompatible pointer types assigning to 'UIViewController *' from 'CalculatorViewController *'

以下错误来自:

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

CalculatorViewController.m: warning: Semantic Issue: Implicit conversion from enumeration type 'UIDeviceOrientation' to different enumeration type 'UIInterfaceOrientation'

最佳答案

对于前 2 个错误:

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

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

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

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

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

您会注意到 UIInterfaceOrientationUIDeviceOrientation 具有相反的值(对于两者共有的枚举;当然对于 UIDeviceOrientationFaceUp UIDeviceOrientationFaceDown没有对应的UIInterfaceOrientation)

关于ios - 警告 : passing incompatible type to setRootViewController:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558583/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com