tags:

views:

67

answers:

1

I am making an app the iPhone. I have a text field the user can type into and it's working, but I want it so you can press a button and it saves the text so when you close and open the app again it is still there. I have the button ("Done!"), but I don't know how to program it.

+1  A: 

Look into the NSUserDefaults class for easy ways to save simple data.

And to get the "done" button on the keyboard to respond, you need to implement the UITextFieldDelegate (or UITextViewDelegate) protocol and override the textFieldShouldReturn: method.

In that method write something like:

- (bool)textViewShouldReturn:(UITextView *)textView
{
    [textField resignFirstResponder];

    //code to save text to NSUserDefaults

    return yes;
}
Jasarien
Sorry to keep blabbering, but the code that you put in there, where does it go? (Also do I have to give the button like a name or something?)
Aidan
I'd recommend a thorough read of the following pieces of documentation:http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html - Apple's Objective-C guidehttp://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextField_Class/ - UITextField class referencehttp://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/ - NSUserDefaults class referencehttp://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/UserDefaults/Tasks/UsingDefaults.html -using defaults
Jeff Kelley
I'd also recommend looking at the "getting started" resources linked to here: http://stackoverflow.com/questions/1939/howto-articles-for-iphone-development-objective-c , as well as in many other questions related to starting out with iPhone programming here on Stack Overflow.
Brad Larson
Yeah, what those guys said ;)
Jasarien