What I expect to do is :
We have ViewController1,2,3. and both ViewController1 & 2 have a button to add a subview to ViewController3,and there also is a button in ViewController3.
Moreover ViewController1 has a function called :-(void)helloWorld{NSLog(....)}
and ViewController2 has a function called : -(void)goodByeWorld{NSLog(.....)}.
I want the effect that if we press the button in ViewController3 and ViewController3 will have different reaction to it based who is the superview(1 or 2) of viewController3.
That is if ViewController3 is added by viewController1, ViewController3 would call "helloWorld" function. On the other hand, If ViewController3 is added by ViewController2, it would call "goodByeWorld".
I could achieve this by a complex and stupid way, that is I make many dirty work such predifined function name and many global information.
But I want to know if there is a solution that I could transmit "helloWorld" or "goodByeWorld" function as a variable to ViewController3, so ViewController3 could have a "pointer(I don't know what type may use..)" to point this function.
As a result, After any presses the button of ViewController3, it could just simply call the function pointed by the pointer and achieve this goal.
I has this idea because we can set the button selector to a function, but I don't have any idea why to implement this method in practice.
Could anyone gives me some idea or suggestion?
I will appreciate you~
THX!