UIViewController在prepareForSegue上抛出无法识别的选择器异常 [英] UIViewController throwing unrecognized selector exception on prepareForSegue

查看:120
本文介绍了UIViewController在prepareForSegue上抛出无法识别的选择器异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试跟随斯坦福CS193p iOS编程讲座。其中一个名为Happiness的演示程序创建了两个UIViewControllers,一个PsychViewController和一个HappinessViewController。它使用目标操作方法从PsychViewController切换到HappinessViewController。

I'm trying to follow along the Stanford CS193p iOS programing lectures. One of the demo programs, called "Happiness" creates two UIViewControllers, a "PsychViewController" and a "HappinessViewController." It segues from the PsychViewController to the HappinessViewController using a target action method.

以下代码不断抛出此异常: - [UIViewController setHappiness:]:无法识别的选择器发送到实例

The following code keeps throwing this exception: "-[UIViewController setHappiness:]: unrecognized selector sent to instance"

这是有问题的代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowDiagnosis"]) {
    [segue.destinationViewController setHappiness:7];
}
}

我搜索了这个网站和其他人,通常当出现此错误时,这是​​因为通用UIViewController尚未正确设置为程序中使用的特定视图控制器对象,在本例中为HappinessViewController。但我已经使用IB中的身份检查器将通用UIViewController设置为HappinessViewController,我仍然得到异常。我正在撕扯我的头发,如果有人可以提供帮助,我将非常感激。

I have searched this site and others, and the usually when this error comes up, it is because the generic UIViewController has not been correctly set to the specific view controller object used in the program, in this case the "HappinessViewController." But I have set the generic UIViewController to be a HappinessViewController using the identity inspector in IB, and I am still getting the exception. I am tearing my hair out, if anyone could help it would be much appreciated.

推荐答案

我发现了问题所在。虽然我已经正确地指定了相关的UIViewController是一个HappinessViewController,但链接器由于某种原因而没有链接到正确的文件。解决方法是双击Xcode中的.xcodeproj文件,然后转到Build Phases并手动添加Compile Sources下的文件。

I figured out the problem. Although I had correctly specified that the relevant UIViewController was a HappinessViewController, the linker, was for some reason, not linking to the correct files. The fix was to go to double click on the .xcodeproj file inside Xcode, then go to Build Phases and manually add the files under "Compile Sources."

这篇关于UIViewController在prepareForSegue上抛出无法识别的选择器异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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