如何保存和加载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)检查说明{
-(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屋!