从父 iOS 访问容器视图控制器 [英] Access Container View Controller from Parent iOS

查看:23
本文介绍了从父 iOS 访问容器视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS6 中,我注意到了新的容器视图,但不太确定如何从包含视图访问它的控制器.

in iOS6 I noticed the new Container View but am not quite sure how to access it's controller from the containing view.

场景:

我想从包含容器视图的视图控制器访问警报视图控制器中的标签.

I want to access the labels in Alert view controller from the view controller that houses the container view.

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

There's a segue between them, can I use that?

推荐答案

是的,您可以使用 segue 来访问子视图控制器(及其视图和子视图).使用 Storyboard 中的属性检查器为 segue 提供一个标识符(例如 alertview_embed).然后让父视图控制器(容纳容器视图的那个)实现一个这样的方法:

Yes, you can use the segue to get access the child view controller (and its view and subviews). Give the segue an identifier (such as alertview_embed), using the Attributes inspector in Storyboard. Then have the parent view controller (the one housing the container view) implement a method like this:

- (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 访问容器视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆