Possible Duplicate:
How would I save and load a UITextField?
我已经尝试了所有方法,但不幸的是,没有任何方法适用于我。我可能已经测试了大约10种保存和加载UITextField的方法,但是它们不起作用。我有六个UITextField,想在按下按钮时保存它们,并在调用viewDidLoad时加载。
请在第二天或两天之内发布该应用程序,但我仍然无法做到这一点,请问我有什么帮助...
谢谢,
詹姆士
最佳答案
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
NSString* textField1Text = textField1.text;
[defaults setObject:textField1Text forKey:@"textField1Text"];
NSString* textField2Text = textField2.text;
[defaults setObject:textField2Text forKey:@"textField2Text"];
NSString* textField3Text = textField3.text;
[defaults setObject:textField3Text forKey:@"textField3Text"];
NSString* textField4Text = textField4.text;
[defaults setObject:textField4Text forKey:@"textField4Text"];
NSString* textField5Text = textField5.text;
[defaults setObject:textField5Text forKey:@"textField5Text"];
NSString* textField6Text = textField6.text;
[defaults setObject:textField6Text forKey:@"textField6Text"];
[defaults synchronize];
NSString* temp = [defaults objectForKey:@"textField1Text"];
NSString* temp = [defaults objectForKey:@"textField2Text"];
NSString* temp = [defaults objectForKey:@"textField3Text"];
NSString* temp = [defaults objectForKey:@"textField4Text"];
NSString* temp = [defaults objectForKey:@"textField5Text"];
NSString* temp = [defaults objectForKey:@"textField6Text"];
NSLog(@"%@,%@,%@,%@,%@,%@",temp1,temp2,temp3,temp4,temp5,temp6);
- (IBAction) saveBtnPresssed : (id) sender
{
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
NSString* textField1Text = textField1.text;
[defaults setObject:textField1Text forKey:@"textField1Text"];
NSString* temp = [defaults objectForKey:@"textField1Text"];
NSLog(@"%@",temp);
}
关于ios - 如何使用NSUserDefaults保存和加载UITextField? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7318167/