From within a view controller in a container view, how do you access the view controller containing the container?(从容器视图的视图控制器中,如何访问包含容器的视图控制器?)
问题描述
这很难用词,但我有一个包含容器视图的视图控制器 (vc1)(我正在使用情节提要).在该容器视图中是一个导航控制器和一个根视图控制器 (vc2).
This is tricky to word but I have a view controller (vc1) that contains a container view (I'm using storyboards). Within that container view is a navigation controller and a root view controller (vc2).
如何从 vc2 中访问 vc1?
From within the vc2 how can I get access to vc1?
或者,我如何将 vc1 传递给 vc2?(请记住,我正在使用情节提要).
Or, how do I pass vc1 to vc2? (baring in mind that I'm using storyboards).
推荐答案
您可以使用 Vc1 中的 prepareForSegue 方法,因为将 ContainerViewController 设为子级时会发生嵌入 segue.您可以将 self 作为 obj 传递或存储对孩子的引用以供以后使用.
You can use the prepareForSeguemethod in Vc1 as an embed segue occurs when the ContainerViewController is made a child. you can pass self as an obj or store a reference to the child for later use.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString * segueName = segue.identifier;
if ([segueName isEqualToString: @"embedseg"]) {
UINavigationController * navViewController = (UINavigationController *) [segue destinationViewController];
Vc2 *detail=[navViewController viewControllers][0];
Vc2.parentController=self;
}
}
次要代码修复
这篇关于从容器视图的视图控制器中,如何访问包含容器的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从容器视图的视图控制器中,如何访问包含容器的视图控制器?
基础教程推荐
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
