我将如何保存和加载 UITextField?
我到处搜索并尝试了很多代码,但似乎没有什么对我有用。我需要做的就是加载(在 viewDidLoad 上)一个文本字段并在按下按钮时保存它。
执行此操作的最简单方法是什么?我正在使用单窗口应用程序,我没有视图控制器(这可能会有所不同?)
谢谢,
詹姆斯
I have searched everywhere and tried lots of code but nothing seems to be working for me. All I need to do is to load (on viewDidLoad) a text field and save it when a button is pressed.
What is the easiest method of doing this? I am working with a single window application, I don't have a view controller (this may make a difference?)
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个 NSMutableDictionary 作为属性,然后...
单击按钮时:
在 viewDidLoad 上,您可以通过以下方式获取文件的值:
Create a NSMutableDictionary as property and ...
when your button is clicked:
On your viewDidLoad, you can get the value of the file by:
使用专门为此场景创建的 NSUserDefaults 类。
该值跨会话存储。
您也可以存储其他值类型(NSString 除外)。
对要存储值的每个字段使用不同的键。
这也可用于存储应用程序配置/选项/等
Use the NSUserDefaults class which was specifically made for this scenario.
The value is stored across sessions.
You can store other value types as well (other than NSString).
Use a different key for each field for which you want to store values.
This can also be used to store app configurations/options/etc
使用 SQLite 数据库:
-(IBAction) checkNotes{
}
您可以尝试一下并根据您的需要调整此代码。
要实现 SQLite3,请检查网络。但我想这对你将来会有很大帮助。我认为这将是最灵活的,因为它还允许您创建关系数据库。
Using an SQLite database:
-(IBAction) checkNotes{
}
You can play around a little bit and adapt this code to your needs.
For implementing SQLite3, check the net. But it will help you much in the future I guess. I think it would be the most flexible, because it will also allow you to create relational databases.