2012-04-29 46 views
0

我對sqlite很新,我一直在試圖讓sqlite輸出到UIcomponents無濟於事。我有一種輕微的感覺,它的語法。任何指針?提前Thanx。 sql結構: |行數|問題|答案| CHOICE1 | CHOICE2 | CHOICE3 | CHOICE4 |無法讓sqlite顯示輸出

.H:

@property (nonatomic) NSInteger *q_num; 
@property (nonatomic, copy) NSString *q; 
@property (nonatomic, copy) NSString *c1; 
@property (nonatomic, copy) NSString *c2; 
@property (nonatomic, copy) NSString *c3; 
@property (nonatomic, copy) NSString *c4; 

.M:

//Reopening path to DB for data acq 
[self filePath]; 
int row = 1; 
NSString *queryRow1 = [NSString stringWithFormat: @"SELECT * FROM QUESTIONBANK WHERE ROW = 1", row]; 
sqlite3_stmt *statement; 
if (sqlite3_prepare_v2(db, [queryRow1 UTF8String], -1, &statement, nil) == SQLITE_OK) { 
    q_num = (NSInteger *)sqlite3_column_int(statement, 0); 
    q = (NSString *)sqlite3_column_text(statement, 1); 
    //omit (statement, 2) since it is the answer 
    c1 = (NSString *)sqlite3_column_text(statement, 3); 
    c2 = (NSString *)sqlite3_column_text(statement, 4); 
    c3 = (NSString *)sqlite3_column_text(statement, 5); 
    c4 = (NSString *)sqlite3_column_text(statement, 6); 
} 

//Question no.1 
//Label for no.1 
scrollViewFrame = CGRectMake(10, 50, 20, 20); 
UILabel *no1 = [[UILabel alloc]initWithFrame:scrollViewFrame]; 
no1.backgroundColor = [UIColor clearColor]; 
no1.font = [UIFont fontWithName:@"Helvetica" size:21]; 
NSString *questionNumber = [NSString stringWithFormat:@"%d", q_num]; 
no1.text = questionNumber; 
[scrollView addSubview:no1]; 
[no1 release]; 

scrollViewFrame = CGRectMake(10, 50, 290, 20); 
UILabel *question = [[UILabel alloc]initWithFrame:scrollViewFrame]; 
question.backgroundColor = [UIColor clearColor]; 
question.font = [UIFont fontWithName:@"Helvetica" size:21]; 
question.text = q; 
[scrollView addSubview:question]; 
[question release]; 

scrollViewFrame = CGRectMake(10, 50, 290, 20); 
UILabel *choice1 = [[UILabel alloc]initWithFrame:scrollViewFrame]; 
choice1.backgroundColor = [UIColor clearColor]; 
choice1.font = [UIFont fontWithName:@"Helvetica" size:21]; 
choice1.text = c1; 
[scrollView addSubview:choice1]; 
[choice1 release]; 

scrollViewFrame = CGRectMake(10, 50, 290, 20); 
UILabel *choice2 = [[UILabel alloc]initWithFrame:scrollViewFrame]; 
choice2.backgroundColor = [UIColor clearColor]; 
choice2.font = [UIFont fontWithName:@"Helvetica" size:21]; 
choice2.text = c2; 
[scrollView addSubview:choice2]; 
[choice2 release]; 

scrollViewFrame = CGRectMake(10, 50, 290, 20); 
UILabel *choice3 = [[UILabel alloc]initWithFrame:scrollViewFrame]; 
choice3.backgroundColor = [UIColor clearColor]; 
choice3.font = [UIFont fontWithName:@"Helvetica" size:21]; 
choice3.text = c3; 
[scrollView addSubview:choice3]; 
[choice3 release]; 

scrollViewFrame = CGRectMake(10, 50, 290, 20); 
UILabel *choice4 = [[UILabel alloc]initWithFrame:scrollViewFrame]; 
choice4.backgroundColor = [UIColor clearColor]; 
choice4.font = [UIFont fontWithName:@"Helvetica" size:21]; 
choice4.text = c4; 
[scrollView addSubview:choice4]; 
[choice4 release]; 

我沒有正確對齊的UIComponents,你可以看到。只是想在我安排他們在適當的地方之前,看看它是否有效。我也很感謝任何批評我的方式編碼部分。我再次感謝您的時間...

+0

我認爲NSInteger不需要(*)符號。 –

回答

0

我認爲你應該在(.M)以下我的代碼解決您的代碼文件與UTF8

q_num = sqlite3_column_int(statement,0); 
q = [NSString stringWithUTF8String:(char *)sqlite3_column_text (statement,1)]; 

使用NSString格式。