我将如何保存和加载 UITextField? [英] How would I save and load a 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?)
谢谢,
詹姆斯
推荐答案
使用 SQLite 数据库:
Using an SQLite database:
-(IBAction) checkNotes{
-(IBAction) checkNotes{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat: @"SELECT Notes FROM NotesTable WHERE UserID = ("%@")", userID.text];
const char *query_stmt = [querySQL UTF8String];
sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_ROW) {
NSString *notesField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
Notes.text = notesField;
[notesField release];
}else{
Status.text = @"Not found";
}
sqlite3_finalize(statement);
}
sqlite3_close(contactDB);
}
您可以尝试一下,然后根据您的需要调整此代码.要实现 SQLite3,请查看网络.但我想它会在未来对你有很大帮助.我认为这将是最灵活的,因为它还允许您创建关系数据库.
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.
这篇关于我将如何保存和加载 UITextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!