在没有警告消息的情况下在父控制器上调用方法

Pat*_*cia 1 iphone objective-c compiler-warnings uiviewcontroller parentviewcontroller

我有一个前视图和翻转视图很像实用天气应用程序.

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

[self.parentViewController returningFromGetStringView];
Run Code Online (Sandbox Code Playgroud)

警告(显示两次):

'UIViewController' may not respond to '-returningFromGetStringView'
'UIViewController' may not respond to '-returningFromGetStringView'
Run Code Online (Sandbox Code Playgroud)

该方法肯定存在...并执行良好...但为什么警告???

Dav*_*vid 6

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

[(id)self.parentViewController returningFromGetStringView]; 
Run Code Online (Sandbox Code Playgroud)

要么

[(YourClassThatIsParent*)self.parentViewController returningFromGetStringView];
Run Code Online (Sandbox Code Playgroud)