私はiDeviceアプリの開発に比較的慣れていません。インターネットで広範囲に検索した後、最終的に答えのない質問にたどり着きました。
ユーザーがテキストフィールドに情報を入力し、スイッチをオンにしてから、アプリを完全に終了して再度開き、情報がまだそこにある「メモアプリ」を開発しています。つまり、「保存」ボタンがありません。これは可能ですか?そして、すべての情報を破棄するための「リセット」ボタンがあるかもしれません。
現在、Xcode 4.5 を使用しています。ヒントを教えてくれる賢い xcoder はいますか?
すべての助けに深く感謝します!
編集
保存/読み込み機能を使用したところ、奇妙なことが起こりました。何が起こるかというと、すべてのテキストフィールド (12 個あります) に何かを入力し、保存してアプリを終了します。アプリを再度開いて、[テキスト フィールド 12 からテキストを読み込む] をクリックすると、テキスト フィールド 1 に読み込まれます。他のすべてのテキストはなくなります。誰にも手がかりがありますか?
時間がある人のために、コードを次に示します。
SecondViewController.h
@interface SecondViewController : UIViewController <UITextFieldDelegate> {
IBOutlet UITextField *myTextField;
IBOutlet UITextField *myTextField2;
IBOutlet UITextField *myTextField3;
IBOutlet UITextField *myTextField4;
IBOutlet UITextField *myTextField5;
IBOutlet UITextField *myTextField6;
IBOutlet UITextField *myTextField7;
IBOutlet UITextField *myTextField8;
IBOutlet UITextField *myTextField9;
IBOutlet UITextField *myTextField10;
IBOutlet UITextField *myTextField11;
IBOutlet UITextField *myTextField12;
IBOutlet UILabel *loaded; }
-(IBAction)save:(id)sender;
-(IBAction)load:(id)sender;
SecondViewController.m
@implementation SecondViewController
-(IBAction)save:(id)sender{
//First Save String
NSString *savestring =myTextField.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"saveString"];
[defaults synchronize];
//Second Save String
NSString *savestring2 =myTextField2.text;
NSUserDefaults *defaults2 = [NSUserDefaults standardUserDefaults];
[defaults2 setObject:savestring2 forKey:@"saveString2"];
[defaults2 synchronize];
//Third Save String
NSString *savestring3 =myTextField3.text;
NSUserDefaults *defaults3 = [NSUserDefaults standardUserDefaults];
[defaults3 setObject:savestring3 forKey:@"saveString3"];
[defaults3 synchronize];
//Fourth Save String
NSString *savestring4 =myTextField4.text;
NSUserDefaults *defaults4 = [NSUserDefaults standardUserDefaults];
[defaults4 setObject:savestring4 forKey:@"saveString4"];
[defaults4 synchronize];
//Fifth Save String
NSString *savestring5 =myTextField5.text;
NSUserDefaults *defaults5 = [NSUserDefaults standardUserDefaults];
[defaults5 setObject:savestring5 forKey:@"saveString5"];
[defaults5 synchronize];
//Sixth Save String
NSString *savestring6 =myTextField6.text;
NSUserDefaults *defaults6 = [NSUserDefaults standardUserDefaults];
[defaults6 setObject:savestring6 forKey:@"saveString6"];
[defaults6 synchronize];
//Seventh Save String
NSString *savestring7 =myTextField7.text;
NSUserDefaults *defaults7 = [NSUserDefaults standardUserDefaults];
[defaults7 setObject:savestring7 forKey:@"saveString7"];
[defaults7 synchronize];
//Eight Save String
NSString *savestring8 =myTextField8.text;
NSUserDefaults *defaults8 = [NSUserDefaults standardUserDefaults];
[defaults8 setObject:savestring8 forKey:@"saveString8"];
[defaults8 synchronize];
//Ninth Save String
NSString *savestring9 =myTextField9.text;
NSUserDefaults *defaults9 = [NSUserDefaults standardUserDefaults];
[defaults9 setObject:savestring9 forKey:@"saveString9"];
[defaults9 synchronize];
//Tenth Save String
NSString *savestring10 =myTextField10.text;
NSUserDefaults *defaults10 = [NSUserDefaults standardUserDefaults];
[defaults10 setObject:savestring10 forKey:@"saveString10"];
[defaults10 synchronize];
//Eleventh Save String
NSString *savestring11 =myTextField11.text;
NSUserDefaults *defaults11 = [NSUserDefaults standardUserDefaults];
[defaults11 setObject:savestring11 forKey:@"saveString11"];
[defaults11 synchronize];
//Twelvth Save String
NSString *savestring12 =myTextField12.text;
NSUserDefaults *defaults12 = [NSUserDefaults standardUserDefaults];
[defaults12 setObject:savestring12 forKey:@"saveString12"];
[defaults12 synchronize];
loaded.text = @"Dine notater ble lagret!"; }
-(IBAction)load:(id)sender;{
//First Load String
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:@"saveString"];
[myTextField setText:loadstring];
[loaded setText:@"Dine notater ble lastet inn!"];
//Second Load String
NSUserDefaults *defaults2 = [NSUserDefaults standardUserDefaults];
NSString *loadstring2 = [defaults2 objectForKey:@"saveString2"];
[myTextField setText:loadstring2];
[loaded setText:@"Dine notater ble lastet inn!"];
//Third Load String
NSUserDefaults *defaults3 = [NSUserDefaults standardUserDefaults];
NSString *loadstring3 = [defaults3 objectForKey:@"saveString3"];
[myTextField setText:loadstring3];
[loaded setText:@"Dine notater ble lastet inn!"];
//Forth Load String
NSUserDefaults *defaults4 = [NSUserDefaults standardUserDefaults];
NSString *loadstring4 = [defaults4 objectForKey:@"saveString4"];
[myTextField setText:loadstring4];
[loaded setText:@"Dine notater ble lastet inn!"];
//Fifth Load String
NSUserDefaults *defaults5 = [NSUserDefaults standardUserDefaults];
NSString *loadstring5 = [defaults5 objectForKey:@"saveString5"];
[myTextField setText:loadstring5];
[loaded setText:@"Dine notater ble lastet inn!"];
//Sixth Load String
NSUserDefaults *defaults6 = [NSUserDefaults standardUserDefaults];
NSString *loadstring6 = [defaults6 objectForKey:@"saveString6"];
[myTextField setText:loadstring6];
[loaded setText:@"Dine notater ble lastet inn!"];
//Seventh Load String
NSUserDefaults *defaults7 = [NSUserDefaults standardUserDefaults];
NSString *loadstring7 = [defaults7 objectForKey:@"saveString7"];
[myTextField setText:loadstring7];
[loaded setText:@"Dine notater ble lastet inn!"];
//Eight Load String
NSUserDefaults *defaults8 = [NSUserDefaults standardUserDefaults];
NSString *loadstring8 = [defaults8 objectForKey:@"saveString8"];
[myTextField setText:loadstring8];
[loaded setText:@"Dine notater ble lastet inn!"];
//Ninth Load String
NSUserDefaults *defaults9 = [NSUserDefaults standardUserDefaults];
NSString *loadstring9 = [defaults9 objectForKey:@"saveString9"];
[myTextField setText:loadstring9];
[loaded setText:@"Dine notater ble lastet inn!"];
//Tenth Load String
NSUserDefaults *defaults10 = [NSUserDefaults standardUserDefaults];
NSString *loadstring10 = [defaults10 objectForKey:@"saveString10"];
[myTextField setText:loadstring10];
[loaded setText:@"Dine notater ble lastet inn!"];
//Eleventh Load String
NSUserDefaults *defaults11 = [NSUserDefaults standardUserDefaults];
NSString *loadstring11 = [defaults11 objectForKey:@"saveString11"];
[myTextField setText:loadstring11];
[loaded setText:@"Dine notater ble lastet inn!"];
//Twelvth Load String
NSUserDefaults *defaults12 = [NSUserDefaults standardUserDefaults];
NSString *loadstring12 = [defaults12 objectForKey:@"saveString12"];
[myTextField setText:loadstring12];
[loaded setText:@"Dine notater ble lastet inn!"];
}
ノルウェー人じゃない人向け!「ダイン・ノタター・ブル・ラステット・イン!」と「Dine notater ble lagret!」保存およびロードを意味します。
繰り返しますが、もし誰かがこれらに目を通す時間があれば、私はとても感謝しています!