在父控制器上回调方法而不显示警告消息

发布于 2024-09-28 12:14:19 字数 421 浏览 2 评论 0原文

我有一个前视图和一个翻转视图,就像实用的天气应用程序一样。

为了避免处理协议的复杂性......在我的 FlipView 上,我需要调用一些驻留在我的前视图上的代码。这有效...但在编译过程中会生成警告。

[self.parentViewController returningFromGetStringView];

警告(显示两次):

'UIViewController' may not respond to '-returningFromGetStringView'
'UIViewController' may not respond to '-returningFromGetStringView'

该方法肯定存在...并且执行得很好...但是为什么会出现警告???

I have a front-view and a flip-view much like the utility weather-app.

To avoid dealing with the complexities of protocols... on my flipView I need to call some code that resides back on my front-view. This works... but generates a warning during compile.

[self.parentViewController returningFromGetStringView];

Warnings (shows twice):

'UIViewController' may not respond to '-returningFromGetStringView'
'UIViewController' may not respond to '-returningFromGetStringView'

The method definitely exists... and executes fine... but why the warning???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我闹别瞎闹 2024-10-05 12:14:19

编译器告诉您它无法验证接收者是否会处理该消息(returningFromGetStringView)。您可以通过强制转换为 id 或强制转换为 ParentViewController 的类型来隐藏它:

[(id)self.parentViewController returningFromGetStringView]; 

[(YourClassThatIsParent*)self.parentViewController returningFromGetStringView];

The compiler tells you that it cannot verify that the receiver will handle the message (returningFromGetStringView). You could hush it by casting to id or by casting to the type of your parentViewController:

[(id)self.parentViewController returningFromGetStringView]; 

or

[(YourClassThatIsParent*)self.parentViewController returningFromGetStringView];
樱桃奶球 2024-10-05 12:14:19

属性 parentViewController 被声明为 UIViewController。因此,据编译器所知,它正在尝试将 returningFromGetStringView 消息发送到 UIViewController。由于 UIViewController 未实现 returningFromGetStringView,因此编译器会发出警告。

要消除警告,您可以将 UIViewController 强制转换为自定义类,让编译器知道 parentViewController 引用的是哪个 UIViewController 子类。

[(MyViewController *)self.parentViewController returningFromGetStringView];

The property parentViewController is declared to be a UIViewController. So, as far as the compiler knows, it's trying to send a returningFromGetStringView message to a UIViewController. Since UIViewController doesn't implement returningFromGetStringView, the compiler gives a warning.

To make the warning go away, you can cast the UIViewController to your custom class to let the compiler know which UIViewController subclass parentViewController is referring to.

[(MyViewController *)self.parentViewController returningFromGetStringView];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文