所以我有一个叫做 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;
视图控制器.m
- (void)textFieldDidEndEditing:(UITextField *)textField {
Choice = TextField.text;
[MainPlayer setName:Choice];
NSLog(@"Choice: %@ Name: %@",Choice, MainPlayer.PlayerName);
}
这应该可以工作,除了 NSLog 返回 Choice:(input given) Name: (null)
我试图更改我的代码,但没有任何效果 :P 感谢您的帮助 :)