How would I save and load a UITextField?

前端 未结 3 582
死守一世寂寞
死守一世寂寞 2021-01-26 10:04

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

3条回答
  •  情深已故
    2021-01-26 10:59

    Using an SQLite database:

    -(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);    
    

    }

    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.

提交回复
热议问题