导航时保存数据
当我导航回上一个视图时,如何从 texfield 保存数据?
我已将应用程序设置为在终止时将所有数据保存到 plist,但是当我上下导航视图时,我需要将数据保存到某个位置。有什么建议吗?按下导航栏上的“后退”按钮时保存数据吗?但如何呢?保存到 NSUserDefaults 吗?
how can i save the data in from texfield when i navigate back to previous view?
i have set the app to save all data to plist when terminate but i when i am navigating up and down view, i need to save the data to some place. any suggestion? save data when "back" button at nav bar is press? but how? save to NSUserDefaults?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过使用会话变量?您可以将所有字段存储在会话变量中,每次用户访问该页面时,它都会首先检查会话变量是否已设置。如果是这样,则使用预先填充了会话变量值的输入字段来呈现表单。如果没有,则渲染一个空白表单。
Have you tried to use session variables? You can store all the fields in session vars and everytime a user visits that page, it will first check to see if the session vars are set. If so, render the form with those input fields pre-populated with the session var values. If not, then render a blank form.
您可以考虑将文本字段的内容存储到应用程序委托的
NSString *
实例变量中。最好的位置是 viewDidUnload 方法,前提是您确实保留了文本字段。You may consider storing the contents of the text field to an
NSString *
instance variable of your application delegate. The best place to do so would beviewDidUnload
method, provided that you did retain the text field.如果您使用 NSuserDefaults,当按下后退按钮时,我用它来保存我的表视图数据。 list 是我的 NSMutableArray,它保存我的数据
(void)viewDidDisappear:(BOOL)animated{
[NSKeyedArchiver archiveRootObject:self.list toFile:[self dataFilePath]];
}
If you are using NSuserDefaults i used this to save my tableview data when the back button was pressed. list is my NSMutableArray that holds my data
(void)viewDidDisappear:(BOOL)animated{
[NSKeyedArchiver archiveRootObject:self.list toFile:[self dataFilePath]];
}