我的iPhone游戏有很多循环代码(移动图片,添加分数),这使得它在每个按钮上重复相同的代码时太大了。
这是ViewController.m
视图控制器.h和ViewController.m之间的接口和实现是正确的-运行良好
- (IBAction)button_xx_pressed:(id)sender
{
//trying to call the outsourced code
[self this_is_a_test];
}所以我试着制作外包的循环代码。我不需要返回结果的方法或函数。只需执行一些操作,如NSLog输出.(只是一个测试)。或者在原版中-移动图片,添加分数和其他东西。
,这是外包,h,
#import "Outsourcing.m"
@end,这是外包,m,
#import "Outsourcing.h"
- (void)this_is_a_test {
int test_variable = 999;
NSLog(@"Give me a test output: = %i", test_variable);
}
@end这将缩小我的游戏规模超过80% (非常重要)。我有数千条重复的编程线路,目前我不知道如何处理它。
实际错误消息:
方法声明缺少上下文的=>
M =>方法声明缺少的上下文=> @end必须出现在Objective上下文中
有什么线索吗?非常感谢..。剩下的比赛没问题..。一切都会顺利进行。我很高兴我能让它运行(但是游戏的大小是个问题)。一两个月前,我从未使用过xcode。我只是在VBA方面有一些经验。我想要的和。
=>调用this_is_a_test
=>私有子this_is_a_test()
但我似乎太蠢了-
谢谢
发布于 2012-10-14 15:48:08
@interface Outsourcing : NSObject
- (void)this_is_a_test;
@end#import "Outsourcing.h"
@implementation
- (void)this_is_a_test {
int test_variable = 999;
NSLog(@"Give me a test output: = %d", test_variable);
}
@end你在你的ViewController里这样称呼它:
#import "Outsourcing.h"
...
- (IBAction)button_xx_pressed:(id)sender
{
Outsourcing *outsourcing = [[[Outsourcing alloc] init] autorelease];
//trying to call the outsourced code
[outsourcing this_is_a_test];
}发布于 2012-10-14 15:49:14
你失踪了
@interface Outsourcing : NSObject在您的头文件中(Outsourcing.h ing.h)。移除:
#import "Outsourcing.m"您导入的头文件,而不是源files....You也缺少:
@implementation Outsourcing在您的.m文件中,就在导入声明之后。
https://stackoverflow.com/questions/12883021
复制相似问题