Access modal view controller parent Access modal view controller parent ios ios

Access modal view controller parent


You can access parent by calling:

self.presentingViewController

As per apple documentation:

The view controller that presented this view controller (or its farthest ancestor.)


The way I'd go about something like this is to simply create a delegate. In AskPasswordViewController's header, put

id delegate;

and

@property (nonatomic, assign) id delegate;

Synthesize it in the implementation file. Then after you alloc/init the modal controller, and before you present it, set modalViewController.delegate = self;. Then within the modal controller, you can call self.delegate to get information from the view controller that presented it. I hope this helps


You can always go further back just by calling parentViewController like so:

self.parentViewController.parentViewController .... and so on until you reach the right one.