当我在不使用performSegueWithIdentifier的情况下单击按钮时,不会调用prepareForSegue [英] prepareForSegue is not getting called when I click on a button without using performSegueWithIdentifier

查看:112
本文介绍了当我在不使用performSegueWithIdentifier的情况下单击按钮时,不会调用prepareForSegue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于斯坦福iOS课程,我正在使用模态视图控制器。在演示中,他们有一个按钮可以启动模态视图,当它被单击时,调用函数prepareForSegue。我将代码和实现模仿到我的项目中,唯一的区别是我的演示在iPhone故事板上,而他们的演示在iPad上。

Based on the Stanford iOS course I am playing with modal view controllers. In the demo they have a button that would launch a modal view and when it is clicked the function prepareForSegue is called. I mimicked the code and implementation into my project with the only difference is that my demo is on an iPhone storyboard and theirs is on the iPad.

我注意到,虽然我的模态视图控制器即将出现,但在此之前它并没有调用prepareForSegue。在查看prepareForSegue之前,我搜索了斯坦福项目,看看他们可以在哪里注册任何segue行为,但是没有证据。任何人都可以对此有所了解。我搜索了堆栈溢出,我发现所有用户都缺少performSegueWithIdentifier的调用实现。然而,在斯坦福大学的演示中他们从未这样做过。

I noticed that while my modal view controller is coming up, it does not call prepareForSegue prior to that. I searched the Stanford project to see where they may register any segue behavior before prepareForSegue is called but there is no evidence. Can anyone shed some light on this. I searched stack overflow and all I found were that users were missing the call implementation of performSegueWithIdentifier. However, in the Stanford demo they never do that.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier hasPrefix:@"Create Label"]) {
        AskerViewController *asker = (AskerViewController *)segue.destinationViewController;
        asker.question = @"What do you want your label to say?";
        asker.answer = @"Label Text";
        asker.delegate = self;
    }

}

以下是故事板的示例:

Here is an example of there storyboard:

以下是我的故事板示例:

Here is an example of my storyboard:

在调试器中,当我停在斯坦福演示代码中时,调用堆栈显示故事板正在执行segue操作,我需要在故事板中配置什么才能获得相同的结果?

In the debugger when I stop in the Stanford Demo code the call stack shows that the storyboard is performing a segue action, what do I need to configure in my storyboard to achieve the same result?

推荐答案

嗯,事实证明,我的视图控制器按钮调用模态视图没有正确的类来实现prepareForSegue。它是默认的UIViewController而不是我的自定义类。

Well, as it turns out, my view controller where button calls the modal view did not have the right class where prepareForSegue is implemented. It was the default UIViewController instead of my custom class.

我想出来的方法是在viewDidLoad中设置一个断点,即使这没有破坏,因此我怀疑在故事板中,我没有与实现按钮的视图相关联的正确类。

The way I figured it out was by putting a break point in viewDidLoad and even that was not breaking and thus I suspected that in the storyboard I did not have the right class associated with the view where the button is implemented.

这篇关于当我在不使用performSegueWithIdentifier的情况下单击按钮时,不会调用prepareForSegue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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