2011-07-05 5 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

당신은 데이터베이스 파일을 사용하여 배열을 초기화하려고합니까? 배열을 초기화하는 데 데이터베이스 파일을 사용할 수 있는지 확실하지 않습니다.

왜 필드를 설정하기 위해 프로젝트 배열을 사용하지 않습니까? 성공적으로 채워지는 것 같습니다 당신의 -(void) readProjectsFromDatabase 또한

이 경우, 다음도 field1field2 제대로 인터페이스 빌더에 연결되어 있는지 확인 배열이 실제로 채워되어 있는지 NSLog 문을 넣어하려고

해당 콘센트로

관련 문제