调用上级ViewController的方法

Just like Marsson mentioned, you need to use delegate...

Here is an sample:

In your child view controller .h file:

@protocol ChildViewControllerDelegate <NSObject> - (void)parentMethodThatChildCanCall; @end @interface ChildViewController : UIViewController { } @property (assign) id <ChildViewControllerDelegate> delegate;

In your child view controller .m file:

@implementation ChildViewController @synthesize delegate; // to call parent method: // [self.delegate parentMethodThatChildCanCall];

In parent view controller .h file:

@interface parentViewController <ChildViewControllerDelegate>

In parent view controller .m file:

//after create instant of your ChildViewController childViewController.delegate = self; - (void) parentMethodThatChildCanCall { //do thing }

你可能感兴趣的:(调用上级ViewController的方法)