我正在进行一个测验,该测验在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);
}
答案 0 :(得分:0)
您是否尝试使用数据库文件初始化阵列?我不确定是否可以像这样使用数据库文件来初始化数组。
为什么不使用projects数组来设置字段?它似乎已在您的-(void) readProjectsFromDatabase
还尝试放置NSLog
语句以查看数组是否实际填充,如果是,则还要检查界面构建器中是否正确连接了field1
和field2
到相应的网点