开发者

Getting the results of a method to be placed into another .m file

开发者 https://www.devze.com 2023-03-10 15:45 出处:网络
This may sound easy, but pleas开发者_StackOverflowe, 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 .

This may sound easy, but pleas开发者_StackOverflowe, 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.


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.


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."


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消