Я делаю тест, который читает из базы данных в 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);
}