saveFileViewController.h
#import <UIKit/UIKit.h> @interface saveFileViewController : UIViewController { IBOutlet UILabel *myLabel; IBOutlet UITextField *myTextField; } -(IBAction) SaveString; -(IBAction) LoadString; @end
saveFileViewController.m
#import "saveFileViewController.h" @implementation saveFile2ViewController -(IBAction) SaveString{ NSUserDefaults *myString = [NSUserDefaults standardUserDefaults]; [myString setObject:myTextField.text forKey:@"string"]; [myTextField resignFirstResponder]; myTextField.text = @""; } -(IBAction) LoadString{ NSUserDefaults *myString = [NSUserDefaults standardUserDefaults]; NSString *tempString = [myString stringForKey:@"string"]; myLabel.text = tempString; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end
参考
YouTube - iPhone Programming - Saving/Loading Strings!http://www.youtube.com/watch?v=XWNrnTc3rxs&feature=related&hd=1
詳解 Objective-C 2.0 改訂版: 荻原 剛志 | iPhoneプログラミングUIKit詳解リファレンス: 所 友太, 京セラコミュニケーションシステム株式会社 | iPhone SDK アプリケーション開発ガイド: Jonathan Zdziarski, 近藤 誠 (監訳), 武舎 広幸, 武舎 るみ |
0 件のコメント:
コメントを投稿