Reputation: 3677
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
andinit
newnavigationController
as I am designing my navigationController from Storyboard.
Upvotes: 1
Views: 1131
Reputation: 72420
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 = ...
}
Upvotes: 4
Reputation: 5695
You can simply access the ViewController
embed inside your UINavigationController
using the childViewControllers
property
NSArray *viewControllers = [navigationController childViewControllers];
if (viewControllers.count > 0) {
UIViewController *myViewController = (UIViewController *)[viewControllers firstObject];
}
Upvotes: 4