About
Home > Tutorials Home > Ios > Save Data in NSUserDefaults in iOS

Save Data in NSUserDefaults in iOS

Published on October 17, 2019 8:29:39 PM

SaveData Example

We are an online tutoring company that has laid its foundation in utilizing Multiple Intelligence methodology to understand specific needs and learning styles of a student.This is the ButtonPressed example. In this example we will see how to load another view after pressing button. So let see how it will worked. Another Buttonpress reference you can find out from here ButtonView in iPhone.So that we patch a particular student to a tutor having a compatible teaching style. We have devised a smart online tutoring system to give you measurable results.Schools, cramped with students, fail to give your child the edge, the motivation and the right teacher guidance to help him find the true potential. We at Eonlinetutors.com make sure that your child gets the perfect learning environment to outperform.




Step 1 : Open the XCode and create a new Single View Based Application template. Give the application name "Button Example". Copy this Code to the ViewController.h

#import <UIKit/UIKit.h>

@interface SaveTutorialViewController : UIViewController
{
	IBOutlet UIButton *saveButton;
	IBOutlet UITextField *email;
	IBOutlet UILabel *retrievedData;
}

@property (nonatomic, retain) IBOutlet UIButton	*saveButton;

@property (nonatomic, retain) IBOutlet UITextField *email;

@property (nonatomic, retain) IBOutlet UILabel *retrievedData;

- (IBAction) saveData;

@end

Step 2 : Copy the Following Code into your ViewController.m File.

#import "SaveTutorialViewController.h"

@implementation SaveTutorialViewController

@synthesize saveButton, email, retrievedData;

- (IBAction) saveData
{
	NSString *emailString = email.text;
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	[prefs setObject:emailString forKey:@"email"];
}

- (BOOL) textFieldShouldReturn: (UITextField *) theTextField
{
	[theTextField resignFirstResponder];
	return YES;
}

@end
ALL COMMENTS (2)
Abhishek Bedre 2017-03-28 17:25:15
I have implemented my own "jarvis"....thanks to this example.        
2019-01-03 13:22:19
It is working fine in desktop but not working in android mobile