popViewControllerAnimated 后 UITextField 内容为空 [英] UITextField contents are empty after popViewControllerAnimated

查看:27
本文介绍了popViewControllerAnimated 后 UITextField 内容为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我使用了导航控制器.我的问题是,当我转到上一个视图然后返回到当前视图时,此视图中的所有 TextField 都是空的.

In my app I'm using a navigation controller. My problem is, when I go to previous view and then back to my current view, all TextFields in this view are empty.

当我从导航控制器浏览堆栈时,我不知道如何保存这些值(在文本字段中).

I don't know how to save these values (in textfields) when I navigate through the stack from navigation controller.

这是我调用 popViewControllerAnimated 的方法:

This is my method where I call popViewControllerAnimated:

- (IBAction)swipeBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

推荐答案

在之前视图的 .h 文件中声明一个属性:

In your previous view's .h file declare a property:

@property (noonatomic, retain) YOURVIEWCONTROLLER *secondVC;

然后在您的@implementation 中,合成属性:

then in your @implementation, synthesize the property:

@synthesize secondVC;

然后用以下代码替换您将视图控制器呈现为模态视图的代码:

then replace the code, where you're presenting the view controller as modal view, with this:

if(!secondVC){
    YOURVIEWCONTROLLER *controller=[[YOURVIEWCONTROLLER alloc]init.......];
    [self setSecondVC:controller];
    [controller release];//if you ain't using arc else just set it to nil
    controller=nil;
}
[self presentModalViewController:self.secondVC animated:YES];

'YOURVIEWCONTROLLER' 是包含文本字段的第二个视图控制器类的名称.不要忘记释放 -dealloc 中的 secondVC 属性.希望能帮到你.

'YOURVIEWCONTROLLER' is the name of the second View controller's class which contains textfield. Dont't forget to release the secondVC property in -dealloc. Hope it'd help.

这篇关于popViewControllerAnimated 后 UITextField 内容为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆