ios - 通过 NavigationController 传递数据

标签 ios objective-c uiviewcontroller uinavigationcontroller

我有一个 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 and init new navigationController 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/

相关文章:

objective-c - 无法覆盖简单方法

ios - 在没有 Storyboard 的情况下以编程方式转至导航 Controller

iphone - 用户单击 "assistance"图标后模式文本弹出的最佳方法?

ios - 自动布局 : can't get the frame size of UICollectionViewCell subViews

ios - 为 iOS 应用程序创建常见问题解答页面的最佳方法是什么

objective-c - 旋转图像时保持图像上的文本可读

ios - 从 Objective-C 的 void 中获取值

ios - 滚动时 TableView 行会变得困惑

ios - UIDatePicker 不弹出

ios - 找不到实例方法 '-presentViewController:animated'