首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >外包代码

外包代码
EN

Stack Overflow用户
提问于 2012-10-14 14:13:36
回答 2查看 181关注 0票数 0

我的iPhone游戏有很多循环代码(移动图片,添加分数),这使得它在每个按钮上重复相同的代码时太大了。

这是ViewController.m

视图控制器.h和ViewController.m之间的接口和实现是正确的-运行良好

代码语言:javascript
复制
- (IBAction)button_xx_pressed:(id)sender
{

    //trying to call the outsourced code
    [self this_is_a_test];  

}

所以我试着制作外包的循环代码。我不需要返回结果的方法或函数。只需执行一些操作,如NSLog输出.(只是一个测试)。或者在原版中-移动图片,添加分数和其他东西。

,这是外包,h,

代码语言:javascript
复制
#import "Outsourcing.m"

@end

,这是外包,m,

代码语言:javascript
复制
#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()

但我似乎太蠢了-

谢谢

EN

回答 2

Stack Overflow用户

发布于 2012-10-14 15:48:08

代码语言:javascript
复制
@interface Outsourcing : NSObject

- (void)this_is_a_test;

@end

代码语言:javascript
复制
#import "Outsourcing.h"

@implementation
- (void)this_is_a_test {

    int test_variable = 999;

    NSLog(@"Give me a test output: = %d", test_variable);
}
@end

你在你的ViewController里这样称呼它:

代码语言:javascript
复制
#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];  
}
票数 1
EN

Stack Overflow用户

发布于 2012-10-14 15:49:14

你失踪了

代码语言:javascript
复制
@interface Outsourcing : NSObject

在您的头文件中(Outsourcing.h ing.h)。移除:

代码语言:javascript
复制
#import "Outsourcing.m"

您导入的头文件,而不是源files....You也缺少:

代码语言:javascript
复制
@implementation Outsourcing

在您的.m文件中,就在导入声明之后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12883021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档