弹出到viewcontroller编辑文本

时间:2016-04-01 09:31:48

标签: ios objective-c cocoa-touch

我有ViewcontrollerA作为表单填写页面并执行计算我现在推送新的viewcontrollerB当我弹出ViewcontrollerA现有内容被清除

我的代码是

在viewcontroller A中

JS_skill *skill_VC = [[JS_skill alloc] initWithNibName:@"JS_skill" bundle:nil];
    [[self navigationController] pushViewController:skill_VC animated:NO];

在viewcontroller B中

[self.navigationController popViewControllerAnimated:YES];

1 个答案:

答案 0 :(得分:1)

快速选项是在推送viewcontroller之前将文本字段的值保存在userDefaults中。然后当你在viewWillAppear中返回viewController时,将textfields设置回userDefaults中的内容:

//Just before you push the viewController:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"Example Name" forKey:@"nameTextField"];
[defaults setValue:@"Example Surname" forKey:@"surnnameTextField"];

//In ViewWillAppear:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
textField.text = [defaults valueForKey:@"nameTextField"];
surnameField.text = [defaults valueForKey:@"surnnameTextField"];