ios - 从父 iOS 访问容器 View Controller

在 iOS6 中,我注意到了新的容器 View ,但不太确定如何从包含 View 访问它的 Controller 。

场景:

我想从包含容器 View 的 View Controller 访问警报 View Controller 中的标签。

它们之间有一个segue,我可以使用它吗?

最佳答案

是的,您可以使用 segue 来访问 subview Controller (及其 View 和 subview )。使用 Storyboard 中的属性检查器为 segue 提供一个标识符(例如 alertview_embed)。然后让父 View Controller (包含容器 View 的那个)实现这样的方法:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   NSString * segueName = segue.identifier;
   if ([segueName isEqualToString: @"alertview_embed"]) {
       AlertViewController * childViewController = (AlertViewController *) [segue destinationViewController];
       AlertView * alertView = childViewController.view;
       // do something with the AlertView's subviews here...
   }
}

关于ios - 从父 iOS 访问容器 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13279105/

相关文章:

ios - 如何对字符串进行 URL 编码

objective-c - 洗牌 NSMutableArray 的最佳方法是什么?

objective-c - 为什么 ARC 仍然需要 @autoreleasepool?

ios - Xcode下架构x86_64的重复符号

ios - 使用 iOS 将文本复制到剪贴板

objective-c - respondsToSelector 的 Swift 等价物是什么?

c - Objective-C : BOOL vs bool

ios - UITableViewCell 显示白色背景,在 iOS7 上无法修改

objective-c - Xcode 4.4 发行说明中提到的 "Objective-C Lite

ios - 缩放 MKMapView 以适应注释图钉?