Syed e Hussaini Syed e Hussaini - 16 days ago 8
iOS Question

Passing Data Via NavigationController

I have a

UIViewController
embed in with a
UINavigationController
. I want to present this
viewController
and after presenting I also need Navigation method (Push & Pop) so I am presenting
UINavigationController
instead of
UIViewController
but for that I need to pass custom data to that
ViewController
as of I have no access to that
ViewController
form previous
ViewController
.
Here is my code.

UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"MyNavigationIdentity"]];

[self presentViewController:navigationController animated:YES completion:nil];



P.S I cannot
alloc
and
init
new
navigationController
as I am designing my navigationController from Storyboard.

Answer

You can access your viewController from viewControllers property of UINavigationController.

if (navigationController.viewControllers.count > 0) {
     //Cast UIViewController with your custom Controller
     ViewController *vc = (ViewController*) [navigationController.viewControllers firstObject];
     //Now pass data you want
     vc.passData = ...
}