Call a parent view controller (through a navigationcontroller)

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
}

Leave a Comment