故事板 - 设置代表 [英] Storyboard - setting delegates

查看:140
本文介绍了故事板 - 设置代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在故事板之前,我可以通过将插座拖到课上来设置委托人和数据源。有了故事板,我无法将插座拖到另一个视图控制器上;没有可以响应的目的地。

Before storyboards I was able to set delegates and datasources just by dragging an outlet to a class. With storyboards, I cannot drag the outlet to another view controller; there is no destination that will respond to it.

如果我点击视图控制器对象,我可以在底部看到课程所有者,但是一旦我选择了包含插座的其他视图控制器,旧的选择已经消失了,所以我无法连接这两个。

If I click on a view controller object, I am able to see the class owner at the bottom, but as soon as I select the other view controller containing the outlet, the old selection is gone, so I cannot connect the two.

这个苹果的方式是说我们应该只以编程方式连接?

Is this Apple's way of saying we should only connect them programmatically?

推荐答案

正确。在 prepareForSegue:sender:方法中设置委托或其他数据。以下是一个示例:

Correct. Set the delegate or other data in your prepareForSegue:sender: method. Here is an example:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Check the segue identifier
    if ([segue.identifier isEqualToString:@"showDetail"])
    {
        // Get a reference to your custom view controller
        CustomViewController *customViewController = segue.destinationViewController;

        // Set your custom view controller's delegate
        customViewController.delegate = self;
    }
}

这篇关于故事板 - 设置代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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