xcode storyboard Container View - 如何访问视图控制器 [英] xcode storyboard Container View - How do I access the viewcontroller

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

问题描述

我正在尝试使用情节提要并使事情正常工作.我在现有视图之一中添加了一个容器视图.当我尝试在我的视图控制器 .h 文件(ctrl-drag)中添加对此的引用时,我得到一个 IBOutlet UIView *containerView.我如何获得对容器视图的视图控制器的引用?我需要容器视图控制器,以便我可以将它的委托设置为我的视图控制器,以便它们可以相互交谈".

I'm trying to use storyboard and get things working properly. I've added a a Container View to one of my existing views. When I try to add a reference to this in my view controller .h file (ctrl-drag), I get a IBOutlet UIView *containerView. How do I get a reference to the container view's view controller instead? I need the container view controller so I can set it's delegate to my view's controller so they can "talk" to each other.

我的故事板设置为:

它在我的 .h 文件中被引用为:

And its referenced in my .h file as:

注意 .h 是 UIView,而不是我的 InstallViewController 视图.如何添加对视图控制器的引用?我需要能够设置它的委托.

Notice in the .h that is is a UIView, not my InstallViewController for the view. How do I add a reference to the view controller? I need to be able to set its delegate.

推荐答案

还有另一种解决方案,即为嵌入 segue 指定标识符并在方法 prepareForSegue 中检索相应的视图控制器:

There is another solution by specifying an identifier for the embed segue(s) and retrieve the corresponding view controllers in method prepareForSegue:

这种方式的优点是您不需要依赖添加子视图控制器的特定顺序,因为每个子视图控制器都是通过唯一的 segue 标识符嵌入的.

The advantage of this way is that you needn't rely on a specific order in which your child view controllers are added due to the fact that each child view controller is embedded via an unique segue identifier.

更新 2013-01-17 - 示例

Update 2013-01-17 - Example

- (void) prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
    // -- Master View Controller
    if ([segue.identifier isEqualToString:c_SegueIdEmbedMasterVC])
    {
        self.masterViewController = segue.destinationViewController;
        // ...
    }
    // -- Detail View Controller
    else if ([segue.identifier isEqualToString:c_SegueIdEmbedDetailVC])
    {
        self.detailViewController = segue.destinationViewController;
        // ...
    }
}

c_SegueIdEmbedMasterVC &c_SegueIdEmbedDetailVC 是具有故事板中定义的 segue ID 对应 ID 的常量.

c_SegueIdEmbedMasterVC & c_SegueIdEmbedDetailVC are constants with the corresponding ID of the segue IDs defined in the storyboard.

这篇关于xcode storyboard Container View - 如何访问视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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