Java でしばらくコーディングしているので、OOP には精通していますが、Objective-C で (構文?) 問題が発生しています。ここの他の投稿を見てきましたが、これまでのところ何も役に立ちませんでした。
ボタンを押すだけでプレーヤーの名前を設定するメソッドと、名前を取得して文字列 (NSString*)get_name を返す別のメソッドを持つ "Play_Name.m" という名前のクラスがあります。get_name 関数を呼び出して入力した名前を表示する「Play_ChooseChar.m」という名前の別のクラスもあります。
get_name は、「Play_Name」(所有者) で呼び出すと正しい名前を返しますが、「Play_ChooseChar」で呼び出すと (null) を返します。
//Play_Name code below
#import "Play_Name.h"
@interface Play_Name ()
@end
@implementation Play_Name
@synthesize playerName;
@synthesize textName;
-(IBAction)set:(id)sender {
[self setPlayerName:(self.textName.text)];
if([self.textName.text length] <= 0) {
playerName = @"Player";
NSLog(@"YOUR NAME: %@", playerName);
}
NSLog(@"YOUR NAME: %@", playerName);
}
//...........
@end
//Play_ChooseChar code below
#import "Play_ChooseChar.h"
#import "Play_Name.h"
@interface Play_ChooseChar ()
@end
@implementation Play_ChooseChar
@synthesize display_name;
@synthesize playname;
@synthesize boy;
@synthesize girl;
@synthesize isGirl;
@synthesize isBoy;
bool isGirl = FALSE;
bool isBoy = FALSE;
-(void)theName {
Play_Name *pN = [[Play_Name alloc] init];
[pN setPlayerName: pN.playerName];
NSLog(@"NAME: %@", pN.playerName);
self.display_name.text = pN.playerName;
//display_name.text = @"test";
[pN release];
//............
@end
そのため、実行して自分の名前を入力すると、「Play_ChooseChar」の print ステートメントは「NAME: (null)」を返します。