So I have a NSObject called Player
Player.h
@interface Player : NSObject{
NSString *PlayerName;
}
@property (nonatomic, retain, strong) NSString *PlayerName;
Player.m
@synthesize PlayerName;
And then in my 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);
}
This should work except the NSLog returns
Choice:(input given) Name: (null)
I’ve tried to change my code, but nothing works 😛
Thanks for the help 🙂
it think you are missing this line.
Before set value of instance you need allocate object. you can allocate it in viewDidLoad.
And then set value of instance
OR