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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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-2009, 11:52 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 11
Angry Save State on Text Fields

Hi,

I am new to iphone development and I am currently working on a simple application that no one has touched in the iphone market that I know of...

However... I cannot find anywhere in my book or anywhere in forums on websites that gives a straight forward walkthrough of how to save the state of the Text Field or Text View when the user leaves...

I have seen people talk about NSString etc but then they give no additional information on HOW to implement the code into .h, .m or delegate parts of xcode...

please help me as I am eager to get through the coding part of my app and perfect the appearance...

PLEASEEEE HELP!!

also... if anyone knows of how to change the font and/or size of a View Field it would me much appreciated...

Thank yoooooooooooo!!
stirkles17 is offline   Reply With Quote
Old 08-23-2009, 12:10 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Spend some time looking over the documentation for both UITextField and UITextView. They both have a 'text' property that you use to both set and retrieve a text value. Ex:

Code:
NSString *stringToSave = [myTextField text];

[myTextField setText: loadedString];
How you save it and load it after that depends on what you need. If it is going to be a small amount of data, check out NSUserDefaults.

For the font stuff, again check out the aforementioned documentation. Also, poke around with those items in Interface Builder.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 08-23-2009, 12:47 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 36
Default

This is pretty easy to do. Let's say you have a UITextField that you want people to enter info into and then save. In your header file (.h):

Code:
IBOutlet UITextField *myTextField;

- (IBAction)updateInfo:(id)sender;
Open your view controller .xib file. It will open. In Interface Builder, drag the text field into the view. Then, right click or contol-click "File's Owner" and drag the line to your text field. Select myTextField (this is the name of the text field we declared in the header file.) Then drag a button into the view. Change the button's title to something like Save.

Then go into your implementation (.m):

Code:
- (IBAction)updateInfo:(id)sender{

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:myTextField.text forKey:@"userInfo"];
[defaults synchronize];

}
Here, when the user hits the button, the text they entered into the text field is saved into the user defaults. Good place to store random info. What about when you need to retrieve this info?

Code:
[defaults valueForKey:@"userInfo"];
wakka092 is offline   Reply With Quote
Old 08-23-2009, 05:10 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 11
Default

Quote:
Originally Posted by BrianSlick View Post
Spend some time looking over the documentation for both UITextField and UITextView. They both have a 'text' property that you use to both set and retrieve a text value. Ex:

Code:
NSString *stringToSave = [myTextField text];

[myTextField setText: loadedString];
How you save it and load it after that depends on what you need. If it is going to be a small amount of data, check out NSUserDefaults.

For the font stuff, again check out the aforementioned documentation. Also, poke around with those items in Interface Builder.

Where would i find this documentation?

I have the appress, beginning iphone development book but it doesn't have a designated chapter on saving...
stirkles17 is offline   Reply With Quote
Old 08-23-2009, 05:15 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 11
Default

Quote:
Originally Posted by wakka092 View Post
This is pretty easy to do. Let's say you have a UITextField that you want people to enter info into and then save. In your header file (.h):

Code:
IBOutlet UITextField *myTextField;

- (IBAction)updateInfo:(id)sender;
Open your view controller .xib file. It will open. In Interface Builder, drag the text field into the view. Then, right click or contol-click "File's Owner" and drag the line to your text field. Select myTextField (this is the name of the text field we declared in the header file.) Then drag a button into the view. Change the button's title to something like Save.

Then go into your implementation (.m):

Code:
- (IBAction)updateInfo:(id)sender{

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:myTextField.text forKey:@"userInfo"];
[defaults synchronize];

}
Here, when the user hits the button, the text they entered into the text field is saved into the user defaults. Good place to store random info. What about when you need to retrieve this info?

Code:
[defaults valueForKey:@"userInfo"];

I LOVE YOU WAKKA!!!!!!!!

stirkles17 is offline   Reply With Quote
Old 08-23-2009, 05:16 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Quote:
Originally Posted by stirkles17 View Post
Where would i find this documentation?
Uh, in Xcode, Help menu -> Documentation

Quote:
Originally Posted by stirkles17 View Post
I have the appress, beginning iphone development book but it doesn't have a designated chapter on saving...
Yes it does. Two, actually. 10 & 11.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 08-24-2009, 06:55 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 11
Default

Quote:
Originally Posted by BrianSlick View Post
Uh, in Xcode, Help menu -> Documentation



Yes it does. Two, actually. 10 & 11.
thanks brian

u helped alot

Last edited by stirkles17; 08-29-2009 at 11:04 AM.
stirkles17 is offline   Reply With Quote
Old 08-24-2009, 07:46 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 11
Default

Quote:
Originally Posted by stirkles17 View Post
I LOVE YOU WAKKA!!!!!!!!


wakka... when i put it in... it comes up with about 7 errors...

im confused :P
stirkles17 is offline   Reply With Quote
Reply

Bookmarks

Tags
save, save state, text, text field

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: 339
21 members and 318 guests
ADY, Dani77, Duncan C, e2applets, Herbie, JasonR, keeshux, linkmx, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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