获取要放入另一个 .m 文件中的方法的结果

发布于 2024-11-14 16:48:39 字数 640 浏览 2 评论 0原文

这听起来可能很容易,但是拜托,我是新手。我有一个简单的程序,需要帮助来解决这个问题。我想在方法中获取结果并将其放入另一个 .m 文件中。这是我所拥有的:

CheckRecognizer .m ....

-(int)good {

    if (fieldGoal == NO && fieldGoalPosition == 0) {
        return 0;
    }

    else if (fieldGoal == YES && fieldGoalPosition == 1) {
        return 1;
    }

    else if (fieldGoal == NO && fieldGoalPosition == 2) {
        return 2;
    }

...        
}

然后我的 ViewController .m 中有这个:

fieldGoal1 = [CheckRecognizer good];

我的文件中有 #import "CheckRecognizer.h",但它无法识别“好”方法。你能帮忙吗?我已经尝试了一切,例如命名要在其他 .m 文件中访问的变量,但没有成功。谢谢。

This may sound easy, but please, I am a newbie. I have a simple program that I need help resolving this issue. I would like to get the results in a method and place it into another .m file. Here is what I have:

CheckRecognizer .m
....

-(int)good {

    if (fieldGoal == NO && fieldGoalPosition == 0) {
        return 0;
    }

    else if (fieldGoal == YES && fieldGoalPosition == 1) {
        return 1;
    }

    else if (fieldGoal == NO && fieldGoalPosition == 2) {
        return 2;
    }

...        
}

Then I have this in my ViewController .m:

fieldGoal1 = [CheckRecognizer good];

I have #import "CheckRecognizer.h" in my file, but it won't recognize the 'good' method. Can you please help? I have tried everything, like naming a variable to be accessed in the other .m file with no success. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别把无礼当个性 2024-11-21 16:48:39

要么制定一个好的类方法,
+(int) good { ... }

或在 CheckRecognizer 实例上调用 good ,
[[[CheckRecognizer alloc] init]好];

我强烈建议您浏览 http:// /developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html

either make good a class method,
+(int) good { ... }

or call good on instance of CheckRecognizer ,
[[[CheckRecognizer alloc] init] good];

I strongly suggest you to go through http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html.

魂ガ小子 2024-11-21 16:48:39

您已将方法声明为实例方法,但将其称为类方法。您需要实例化一个实例:

CheckRecognizer *recognizer = [CheckRecognizer alloc] init];

然后使用它:

int result = [recognizer good];

您还应该想出一个比“好”更好的方法名称。

You've declared your method as an instance method, but called it as a class method. You need to instantiate an instance:

CheckRecognizer *recognizer = [CheckRecognizer alloc] init];

And then use it:

int result = [recognizer good];

You should also come up with a better method name than "good."

自我难过 2024-11-21 16:48:39

fieldGoal1 = [[[CheckRecognizer alloc]init]autorelease]good];

现在,如果这是正确的做事方式,那就是一个完全不同的问题了;)

fieldGoal1 = [[[CheckRecognizer alloc]init]autorelease]good];

Now if this is the correct way of doing stuff, that is an entirely different question ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文