获取要放入另一个 .m 文件中的方法的结果
这听起来可能很容易,但是拜托,我是新手。我有一个简单的程序,需要帮助来解决这个问题。我想在方法中获取结果并将其放入另一个 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要么制定一个好的类方法,
+(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.
您已将方法声明为实例方法,但将其称为类方法。您需要实例化一个实例:
然后使用它:
您还应该想出一个比“好”更好的方法名称。
You've declared your method as an instance method, but called it as a class method. You need to instantiate an instance:
And then use it:
You should also come up with a better method name than "good."
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 ;)