【发布时间】:2012-08-22 07:42:23
【问题描述】:
所以我有一个叫做 Player 的 NSObject
Player.h
@interface Player : NSObject{
NSString *PlayerName;
}
@property (nonatomic, retain, strong) NSString *PlayerName;
Player.m
@synthesize PlayerName;
然后在我的 MainViewController.h 中
#import "Player.h"
@interface ViewController : UIViewController<UITextFieldDelegate>{
Player *MainPlayer;
}
@property (weak, nonatomic) IBOutlet UITextField *TextField;
ViewController.m
- (void)textFieldDidEndEditing:(UITextField *)textField {
Choice = TextField.text;
[MainPlayer setName:Choice];
NSLog(@"Choice: %@ Name: %@",Choice, MainPlayer.PlayerName);
}
这应该可以工作,除了 NSLog 返回 选择:(输入给定)名称:(空)
我尝试更改我的代码,但没有任何效果 :P 感谢您的帮助:)
【问题讨论】:
-
我看到在 ViewController.m 中你调用了
[MainPlayer setName: Choice],但在实际的播放器类中该属性被调用为PlayerName。那是错字吗?如果不是,这可能是原因。
标签: objective-c nsstring nstextfield nsobject