Im trying to send a float from one viewcontroller to another.
Ok Ive tried using NSUserDefaults to go about this. First I tested it with a string and it worked, but now I'm struggling to do the same with my float. Any help would be appreciated! :) Heres my code
In my firstviewcontroller.h file i have
IBOutlet UITextField *nameField;
IBOutlet UILabel *greeting;
float RWI;
float Liters;
@property(nonatomic) float *Liters;`
@property(nonatomic, retain); IBOutlet UILabel *greeting;
@property(nonatomic, retain) IBOutlet UITextField *nameField;
-(IBAction) updatePrefs:(id) sender; @property(nonatomic) float *RWI; `
In my .m file I have float RWI; //@synthesize RWI; @synthesize Liters; @synthesize nameField,greeting;
-(IBAction) updatePrefs:(id) sender
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:nameField.text forKey:@"greeting"];
[prefs setFloat:20 forKey:@"Liters"];
[prefs synchronize]
Then for the secondviewcontroller.h file
IBOutlet UILabel *greeting;
float *Liters;
}
@property(nonatomic, retain) IBOutlet UILabel *greeting;
@end`
In my .m file
@implementation secondviewcontroller
@synthesize greeting;
@synthesize Liters;
- (void)viewDidLoad {
[super viewDidLoad];NSString *prefs =
[[NSUserDefaults standardUserDefaults] objectForKey:@"greeting"];
float Liters = [prefs floatForKey:@"Liters"];
greeting.text = prefs;
}`
Why does my float give errors? Any help would be appreciated! :)