2011-07-05 38 views
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); 
    } 
+0

@OMG小馬目標c – mat

回答

0

你們是不是要初始化使用的數據庫文件中的數組?我不確定數據庫文件是否可以像這樣使用來初始化數組。

爲什麼不使用projects數組來設置字段?看來,它成功地被填充在-(void) readProjectsFromDatabase

也可以嘗試把NSLog報表,看看是否實際居住的陣列,如果是的話,也請檢查是否field1field2在界面生成器正確連接到相應的網點

相關問題