我有一个 UIViewController
嵌入 UINavigationController
.我想介绍这个viewController
并且在展示之后我还需要导航方法(Push & Pop)所以我展示UINavigationController
而不是 UIViewController
但为此我需要将自定义数据传递给 ViewController
截至目前,我无法访问该 ViewController
形成上一个 ViewController
.
这是我的代码。
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.
最佳答案
您可以访问您的 viewController
来自 viewControllers
UINavigationController
的属性(property).
if (navigationController.viewControllers.count > 0) {
//Cast UIViewController with your custom Controller
ViewController *vc = (ViewController*) [navigationController.viewControllers firstObject];
//Now pass data you want
vc.passData = ...
}
关于ios - 通过 NavigationController 传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40799092/