是否可以在 Storyboard 中按住 ctrl-drag 来设置 UINavigationControllerDelegate? [英] Is it possible to ctrl-drag in Storyboard to set a UINavigationControllerDelegate?

查看:18
本文介绍了是否可以在 Storyboard 中按住 ctrl-drag 来设置 UINavigationControllerDelegate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 5.0.2 中,我创建了 (上面截图中的登录"标题)是导航控制器的委托,以便其方法

- (void)navigationController:(UINavigationController *)navigationControllerdidShowViewController:(UIViewController *)viewController动画:(BOOL)动画

被调用 - 所以我在它的 viewDidLoad 中添加了以下代码:

UINavigationController *nc = self.navigationController;[nc setDelegate:self];

这可行,但我想知道是否也可以在 Interface Builder 中为导航控制器设置委托?

我已经尝试从导航控制器的黄色立方体标志按住 ctrl 拖动到 LoginViewController 场景,反之亦然 - 但我只提供了一个弹出窗口来创建一个 segue...

解决方案

这个答案可能在 2015 年 12 月已经过时.,这已经不可能了.您可以像以前一样在 viewDidLoad 中以编程方式执行此操作,也可以使用 prepareForSegue:.

In Xcode 5.0.2 I've created an app for iPhone with a navigation controller and 3 further view controllers (here fullscreen):

I'd like the LoginViewController (with the "Login" title in the above screenshot) be the delegate for the navigation controller, so that its method

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated

is called - so I have added the following code to its viewDidLoad:

UINavigationController *nc = self.navigationController;
[nc setDelegate:self];

This works, but I wonder if setting the delegate for the navigation controller is also possible in the Interface Builder?

I've tried ctrl-dragging from the yellow cube sign of the navigation controller to the LoginViewController scene and vice versa - but I'm only offered a popup to create a segue...

解决方案

EDIT: this answer might be outdated as of Dec 2015. This answer is probably more accurate for XCode 6 and newer.

Long long ago, before storyboards existed, setting delegates was possible using outlets (although I don't remember if it was possible for UINavigationController, I only remember that I did it with UITableView). You would just right-click on Navigation Controller and drag from the outlet to the target:

However, according to this answer, it's not possible anymore. You can do it programatically in viewDidLoad as you did, or using prepareForSegue:.

这篇关于是否可以在 Storyboard 中按住 ctrl-drag 来设置 UINavigationControllerDelegate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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