0
我正在從SQL中的數據庫中讀取測驗,並將問題放在標籤視圖和文本框中的答案中。我做了很多有類似解決方案的教程,但他們使用了表格視圖。這裏是我的嘗試,我當然檢查,看看是否我有一個數據庫,並使用:如何把我的數據庫中的數據放入SQL,並將其放在文本字段和標籤上
-(void) readProjectsFromDatabase {
sqlite3 *database;
projects = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from t1";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
field1.text = [array objectAtIndex:0];
field2.text = [array objectAtIndex:1];
// Create a new project object with the data from the database
Project *project = [[Project alloc] initWithName:aName description:aDescription url:aImageUrl];
// Add the project object to the project Array
[projects addObject:project];
[project release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
@OMG小馬目標c – mat