2012-03-27 5 views
-5

イメージ、ビデオ、viewController(.hと.m)と別のファイル(別のファイルをfile2としましょう。 .m)too文字列を.mで使用することはできません

問題は、file2.mのviewController.hの文字列を使用したいのですが、できません。私はこれを試みた:

// ViewController.h 

{ 
    NSString *string; 
} 
@property (nonatomic, retain) NSString *string; 


//ViewController.m 

@synthesize string; 

    // file2.m 

#import"viewController.h" 

- (IBAction)changestring:(id)sender { 
    string = @"something"; 
} 

私は文字列を変更しようとするとエラーが返されます。私は間違って何をしていますか? ありがとうございました!

+2

XCodeがあなたの投稿に返すエラーを指定する必要があります。 – Joe

+0

未定義の識別子 'string'の使用 –

+0

私の編集された回答を参照してください。 –

答えて

0

この

viewController.h 

{ 
NSString *string; 
} 
@property (nonatomic, retain) NSString *string; 

ようなインターフェイスの外viewController.hであなたの文字列のプロパティを追加し、あなたが輸入し、他のファイルでその文字列をアクセスできるように

viewController.m 

@synthesize string; 

でそれを合成あなたのviewController.h

編集:

あなたのviewController.hのオブジェクトをfile2に作成し、このようにアクセスします。

file2.h 
    { 
viewController *viewCont; 
} 
    file2.m 

#import"viewController.h" 

-(IBAction)changestring:(id)sender 
    { 
     [email protected]"something"; 
} 
+0

私はすでにこれをやっている –

+0

それでは、あなたはどんなエラーを受けていますか? –

+0

宣言されていない識別子 'string'の使用 –

関連する問題