0

私が試したコードを投稿しています。文字列値を取得してから、それを配列に追加して配列値も取得しています。しかし、他の方法で配列値を使用しようとすると問題が発生し、値が空白になります。

//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=[[NSMutableArray alloc]init];
                [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] ここに:( ) //皆さん、なぜこれが起こっているのか、コードに間違いがあるのか​​ 、あなたの助けが必要です.

4

1 に答える 1

0

TableVideoIDArray が 2 回割り当てられました。

viewDidLoad で、使用

TableVideoIDArray=[NSMutableArray array]; 

While ループで with を割り当てないでください。

于 2013-09-18T06:13:25.083 に答える