我正在发布我尝试过的代码。我正在获取字符串值,但是当将 nsstring 的所有值添加到 nsmutablearray 并打印它时,我得到空值。
//ViewController.h
@interface ViewController : UIViewController{
NSString *stringValueVideoiD;
NSMutableArray *TableVideoIDArray;
}
//ViewController.m
@implementation ViewController
- (void)viewDidLoad
{
TableVideoIDArray=[[NSMutableArray alloc]init];
}
-(void) getAllRows{
if(sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK)
{
NSString *sqlStatement = [NSString stringWithFormat:@"SELECT * FROM table"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(db,[sqlStatement UTF8String] , -1, &compiledStatement, NULL)== SQLITE_OK)
{
while(sqlite3_step(compiledStatement)==SQLITE_ROW)
{
char *videoId = (char *) sqlite3_column_text(compiledStatement, 1);
stringValueVideoiD = [[NSString alloc] initWithUTF8String:videoId];
[TableVideoIDArray addObject:stringValueVideoiD];
NSLog(@"vids id:%@",TableVideoIDArray);
//vids id:(null) is printed
}
}
}
}