xcode 故事板和设置代表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19102399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:58:17  来源:igfitidea点击:

Storyboards and setting delegates

iosxcodeuistoryboard

提问by Buyin Brian

Now that Xcode 5 really encourages you work with storyboards, I'm making that my workflow. However having some trouble understanding initialization and setting delegates. (screen attached of my storyboard)

既然 Xcode 5 真的鼓励你使用故事板,我就把它作为我的工作流程。但是在理解初始化和设置委托时遇到了一些麻烦。(我的故事板的屏幕附加)

I have a Root View controller class that loads a navigation view controller into a container view. I want the root controller of the navigation controllers class to be the root controller of the storyboard. Without a storyboard, this would be incredibly simple.

我有一个根视图控制器类,它将导航视图控制器加载到容器视图中。我希望导航控制器类的根控制器成为故事板的根控制器。如果没有故事板,这将非常简单。

In my root class I would simply write:

在我的根类中,我会简单地写:

AlarmBarVC *aBar =  [[AlarmBarVC alloc]init];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController: aBar];

aBar.delegate = self;

self addChildViewController: navcon];
[self.container addSubview: navcon.view];

Any suggestion on how to implement this with Storyboards?

关于如何使用 Storyboards 实现这一点的任何建议?

Thank you for your time.

感谢您的时间。

enter image description here

在此处输入图片说明

回答by mike

To set RootVC as the delegate to Alarm BarVC, select the Alarm BarVC in storyboard and navigate to the Connections inspector. Assuming you have created a property to hold the delegate in AlarmBarVC.h, you should see a delegate outlet that you can just drag to RootVC.

要将 RootVC 设置为 Alarm BarVC 的代理,请在情节提要中选择 Alarm BarVC 并导航到 Connections 检查器。假设您已经在 AlarmBarVC.h 中创建了一个属性来保存委托,您应该会看到一个委托出口,您可以将其拖到 RootVC。