Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-23-2010, 04:11 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 29
cowgod2007 is on a distinguished road
Default Make keyboard go away in text view and saving data?

Hello,

So I have a simple text view. I want it so that when the user types anything and presses "Done", the stuff they typed will be saved into a global variable. First off, how do I make a "Done" button on the keyboard or even make it go away? What is the code? And also, how do I save the data that was typed into the text field?

Thanks!
cowgod2007 is offline   Reply With Quote
Old 08-24-2010, 06:40 AM   #2 (permalink)
newbieDeveloper
 
Join Date: Aug 2010
Location: Wiltshire, UK
Posts: 5
iStuchbury is on a distinguished road
Send a message via Skype™ to iStuchbury
Default

Quote:
Originally Posted by cowgod2007 View Post
Hello,

So I have a simple text view. I want it so that when the user types anything and presses "Done", the stuff they typed will be saved into a global variable. First off, how do I make a "Done" button on the keyboard or even make it go away? What is the code? And also, how do I save the data that was typed into the text field?

Thanks!
Making the keyboard retract, I can help you with. Saving data - I'm not there yet, so maybe someone else can point you in the right direction.

Presumably, you'll want the keyboard to retract when either the user taps "Done" on the keyboard, or taps the background.

When the user taps "Done"
You'll need an outlet for the UITextField and two IBAction methods in you nib's controller class. We'll use:
Code:
UITextField *textField;
Code:
- (IBAction)textFieldDoneEditing:(id)sender;
and
Code:
- (IBAction)backgroundTap;
I don't know what level you're at, but I'm assuming you know how to define these in the correct places.

Code:
- (IBAction)textFieldDoneEditing:(id)sender {
	[sender resignFirstResponder];
}
Code:
- (IBAction)backgroundTap {
	[textField resignFirstResponder];
        //If you had any other UITextFields, you would tell them to resignFirstResponser as well.  There's no harm in telling an object to resign first responder status if it doesn't hold it.
}
In your nib, connect the UITextField to the new outlet. Then connect the DidEndOnExit event to the textFieldDoneEditing action in File's Owner.

Next, you need to set the Return Key option of the text input traits for the UITextField to "Done". This will make the standard keyboard return key a "Done" key.

When the user taps the background
You need to change the class of the UIView to UIControl. UIControl is a subclass of UIView, so everything else will work, but you will be able to link events on the view to actions in your controller class. Connect the Touch Down event to the backgroundTap event in File's Owner.

After changing the class of the original UIView, you may need to reconnect it to the view outlet in File's Owner.

Saving the TextField to a variable
I assume you want to do more with the entered text than just store it to a temporary variable, so I'll not comment here as I'd be out of my depth.

HTH
iStuchbury is offline   Reply With Quote
Old 08-24-2010, 07:29 AM   #3 (permalink)
Persian Developer
 
Join Date: Mar 2009
Posts: 274
Momeks is on a distinguished road
Default

For save your data on text field you can do this :

//Save Setting ///////////////////
Code:
- (NSString *) saveFilePath
{
	NSArray *pathArray =
	NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	
	return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"savedddata.plist"];
	
}

- (void)applicationWillTerminate:(UIApplication *)application {
	
	NSArray *values = [[NSArray alloc] initWithObjects:textField.text ,nil];
	[values writeToFile:[self saveFilePath] atomically:YES];
	[values release];
	
}

on ViewDidLoad :


Code:
NSString *myPath = [self saveFilePath];
	
	
	BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
	
	if (fileExists)
	{
		
		NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
		textField.text = [values objectAtIndex:0];
		[values release];
	}
	
	// notification
	UIApplication *myApp = [UIApplication sharedApplication];
	
	// add yourself to the dispatch table 
	[[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(applicationWillTerminate:) 
												 name:UIApplicationWillTerminateNotification 
											   object:myApp];

__________________
My Applications On the App Store


Momeks is offline   Reply With Quote
Old 08-24-2010, 08:29 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 29
cowgod2007 is on a distinguished road
Default

Quote:
Originally Posted by Momeks View Post
For save your data on text field you can do this :

//Save Setting ///////////////////
Code:
- (NSString *) saveFilePath
{
	NSArray *pathArray =
	NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	
	return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"savedddata.plist"];
	
}

- (void)applicationWillTerminate:(UIApplication *)application {
	
	NSArray *values = [[NSArray alloc] initWithObjects:textField.text ,nil];
	[values writeToFile:[self saveFilePath] atomically:YES];
	[values release];
	
}

on ViewDidLoad :


Code:
NSString *myPath = [self saveFilePath];
	
	
	BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
	
	if (fileExists)
	{
		
		NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
		textField.text = [values objectAtIndex:0];
		[values release];
	}
	
	// notification
	UIApplication *myApp = [UIApplication sharedApplication];
	
	// add yourself to the dispatch table 
	[[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(applicationWillTerminate:) 
												 name:UIApplicationWillTerminateNotification 
											   object:myApp];

How exactly does this work...? I used the guy up tops method of the quitting the keyboard and it worked perfectly! Thanks! Exactly what i was looking for!
cowgod2007 is offline   Reply With Quote
Old 08-24-2010, 08:36 AM   #5 (permalink)
Persian Developer
 
Join Date: Mar 2009
Posts: 274
Momeks is on a distinguished road
Default

you want store somethingon a textField so when you type words on text field and quit from app ,, your data will save on text filed . and works perfectly like that
__________________
My Applications On the App Store


Momeks is offline   Reply With Quote
Old 08-24-2010, 09:20 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 29
cowgod2007 is on a distinguished road
Default

Thats not exactly what I was looking for...thanks for the help though.

So right now I have a UIAlert pop up window that prompts the user to enter in 2 values. Here is the code:
Code:
-(IBAction)pushButton{
	
	UIAlertView *alert = [[UIAlertView alloc]
						  initWithTitle:@ "Enter in data"
						  message:@""
						  delegate:self
						  cancelButtonTitle:@"Save"
						  otherButtonTitles:nil];
	[alert addTextFieldWithValue:@"" label:@"Threshold"];
	[alert addTextFieldWithValue:@"" label:@"Filter"];
	
	UITextField *tf = [alert textFieldAtIndex:0];
	tf.clearButtonMode = UITextFieldViewModeWhileEditing;
	tf.keyboardType = UIKeyboardTypeAlphabet;
	tf.keyboardAppearance = UIKeyboardAppearanceAlert;
	tf.autocorrectionType=UITextAutocorrectionTypeNo;
	tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
	
	
	tf=[alert textFieldAtIndex:1];
	tf.clearButtonMode = UITextFieldViewModeWhileEditing;
	tf.keyboardType=UIKeyboardTypeURL;
	tf.keyboardAppearance=UIKeyboardAppearanceAlert;
	tf.autocapitalizationType = UITextAutocapitalizationTypeNone;
	tf.autocorrectionType=UITextAutocorrectionTypeNo;
	[alert show];
	
	
	
}
How could I make it so that when the user presses the "Save" button, all the data in the text fields are saved?
cowgod2007 is offline   Reply With Quote
Old 09-02-2010, 02:29 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 54
pinu is on a distinguished road
Default i have the same problem but with table view

Quote:
Originally Posted by cowgod2007 View Post
Thats not exactly what I was looking for...thanks for the help though.

So right now I have a UIAlert pop up window that prompts the user to enter in 2 values. Here is the code:
Code:
-(IBAction)pushButton{
	
	UIAlertView *alert = [[UIAlertView alloc]
						  initWithTitle:@ "Enter in data"
						  message:@""
						  delegate:self
						  cancelButtonTitle:@"Save"
						  otherButtonTitles:nil];
	[alert addTextFieldWithValue:@"" label:@"Threshold"];
	[alert addTextFieldWithValue:@"" label:@"Filter"];
	
	UITextField *tf = [alert textFieldAtIndex:0];
	tf.clearButtonMode = UITextFieldViewModeWhileEditing;
	tf.keyboardType = UIKeyboardTypeAlphabet;
	tf.keyboardAppearance = UIKeyboardAppearanceAlert;
	tf.autocorrectionType=UITextAutocorrectionTypeNo;
	tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
	
	
	tf=[alert textFieldAtIndex:1];
	tf.clearButtonMode = UITextFieldViewModeWhileEditing;
	tf.keyboardType=UIKeyboardTypeURL;
	tf.keyboardAppearance=UIKeyboardAppearanceAlert;
	tf.autocapitalizationType = UITextAutocapitalizationTypeNone;
	tf.autocorrectionType=UITextAutocorrectionTypeNo;
	[alert show];
	
	
	
}
How could I make it so that when the user presses the "Save" button, all the data in the text fields are saved?
Hiiii....i have the same problem.i have created one table with 5 names.when i click on add button it will go to the textview n type the text but i m confused with how to save that text back in table.please someone help me out..Thanks in advance.
pinu is offline   Reply With Quote
Reply

Bookmarks

Tags
field, keyboard, save, text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 340
5 members and 335 guests
freewind, HemiMG, lendo, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:56 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0