0

サーバーにいくつかの値を保存しています。次に、JSON を使用してその値をフェッチし、ローカル データベース テーブルに追加しました。次に、その値を表示して表示する必要があります。ただし、NSLog に表示される配列値。ビューに表示されません。TableView に表示する必要はありません。

コード:

-(void) addDataToArray{


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    //NSLog(@"docs dir is %@", documentsDirectory);

    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"db1.sqlite"];
    //NSLog(@"filepath %@",path);

    mArray = [[NSMutableArray alloc]init];


    if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {

        // const char *sql = "SELECT id,cat_name FROM categories order by order_by";

        const char *sql = "SELECT * FROM categories";

        NSLog(@"Sql is %s",sql);


        sqlite3_stmt *statement;
        int catID = 0;
        if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
            // We "step" through the results - once for each row.
            while (sqlite3_step(statement) == SQLITE_ROW) {


              NSString *catName = [[NSString alloc] initWithUTF8String:
                                     (const char *) sqlite3_column_text(statement, 1)];
                NSLog(@"catName is %@",catName);

                [mArray addObject:catName];

                // [self.view addConstraints:mArray];

                NSLog(@"mArray is %@", mArray);

                [catName release];

                catID = sqlite3_column_int(statement, 0);


            }
        }
        sqlite3_finalize(statement);
    } else {
        sqlite3_close(database);
        NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
        // Additional error handling, as appropriate...
    }
}



- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"connectionDidFinishLoading");
[self addDataToArray];
}

NSログ:

catName is person1
mArray is (
    person1
)

catName is person2

mArray is (
    person1
    person2
)

テキストビュー:

    UITextView *txt=[[UITextView alloc]initWithFrame:CGRectMake(50, 50, 200, 200)];
      //  txt.text=[mArray objectAtIndex:0];
        [self.view addSubview:txt];

for (int i = 0; i<[mArray count]; i++ ) { NSLog(@"index %d",i); }
4

1 に答える 1