开发者

Calling a method back on the parent controller without a warning message

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'
'UIView开发者_如何学JAVAController' may not respond to '-returningFromGetStringView'

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


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];


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜