0

私の iPhone ゲームには繰り返しコード(画像の移動、スコアの追加) がたくさんあり、ボタンをクリックするたびに同じコードを繰り返すとサイズが大きくなりすぎます。

これはViewController.mです

Viewcontroller.h と ViewController.m の間のインターフェースと実装は正しい - うまく動作する

- (IBAction)button_xx_pressed:(id)sender
{

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

}

だから私は外注の繰り返しコードを作ろうとしました。結果を返すメソッドや関数は必要ありません。NSLog出力のようなアクションを実行するだけです...(単なるテスト)。または元のバージョンでは、写真を移動したり、スコアを追加したり、その他のものを追加したりできます。

これは Outsourcing.h です

#import "Outsourcing.m"

@end

これはOutsourcing.mです

#import "Outsourcing.h"


- (void)this_is_a_test {

    int test_variable = 999;

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

}


@end

これにより、ゲームのサイズが 80% 以上縮小されます (非常に重要です)。私は何千もの繰り返しプログラミング行を持っていますが、現時点ではそれを処理する方法がわかりません。

実際のエラー メッセージ:

Outsourcing.h => メソッド宣言のコンテキストがありません

Outsourcing.m => メソッド宣言のコンテキストがありません => @end は Objective-C コンテキストに表示される必要があります

誰でも私に何かヒントはありますか?ありがとうございました...残りのゲームは問題ありません...すべて問題なく動作します。実行できてとてもうれしいです(ただし、ゲームのサイズが問題です)。1、2 か月前、私は xcode を使用したことがありませんでした。VBAの経験が少しありました。そして、私が欲しいのは似ています。

=> this_is_a_test を呼び出します

=> プライベートサブ this_is_a_test()

しかし、私はあまりにも愚かなようです:-(

ありがとう

4

2 に答える 2

1
@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-14T15:48:08.420 に答える
0

あなたが行方不明です

@interface Outsourcing : NSObject

ヘッダー ファイル (Outsourcing.h) で。削除する:

#import "Outsourcing.m"

ソースファイルではなく、ヘッダーファイルをインポートします....次のものもありません:

@implementation Outsourcing

.m ファイルで、インポート宣言の直後。

于 2012-10-14T15:49:14.880 に答える