我正在发布我尝试过的代码。我正在获取字符串值,然后我将它添加到一个数组并获取数组值。但是当我尝试在其他方法中使用数组值时,它的值是空白的。
//ViewController.h
@interface ViewController : UIViewController{
NSString *stringValueVideoiD;
NSMutableArray *TableVideoIDArray;
}
//ViewController.m
@implementation ViewController
- (void)viewDidLoad
{
TableVideoIDArray=[[NSMutableArray alloc]init];
[self getAllRows];
}
-(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 array:%@",TableVideoIDArray);
//vids aray:value is printed
}
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell==nil) {
cell=[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSLog(@"here:%@",TableVideoIDArray);
//here comes the problem.My console result is
2013-09-18
11:18:24.431 TubeAlert[468:11303] here:( ) //so guys I need your help why this is happenning or I am making mistakes in my code.