开发者

populate array in sqlite while

I am doing something fundamental wrong but I am searching for better examples on the net and is coming up short :-(

in .h @interface MyDataViewController : UIViewController {

NSArray *array;
}
@property (nonatomic, retain) NSArray *array;

in m

@synthesize array;

succesful dbretrieval:

while (sqlite3_step(statement) == SQLITE_ROW) {
            //I guess this one is wrong but I cant 开发者_JS百科figure it out.. (tired?)
            array = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];

//testoutput to textfield:
            //myName.text  = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
//testoutput to nslog:
            NSLog(@"Data: %@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]);

        }

Outputs the last from sqlitequeryn:

NSLog(@"%@", array);


What are your output and what do you expect from this? You are directly putting a NSString into a NSArray, of which might, or might not be done several times for a static NSArray.

If you are planning on putting several strings into your array, you should have a NSMutableArray and simply addObject every time you loop through your while:

NSMutableArray *array = [[NSMutableArray alloc] init];
...code....
while (sqlite3_step(statement) == SQLITE_ROW) {
    [array addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜