Iphone 在sqlite中填充数组,同时

Iphone 在sqlite中填充数组,同时,iphone,arrays,xcode,sqlite,populate,Iphone,Arrays,Xcode,Sqlite,Populate,我犯了一些根本性的错误,但我正在网上寻找更好的例子,结果很短:-( in.h @接口MyDataViewController:UIViewController{ NSArray *array; } @property (nonatomic, retain) NSArray *array; 以米计 成功的数据库检索: while (sqlite3_step(statement) == SQLITE_ROW) { //I guess this one is wrong bu

我犯了一些根本性的错误,但我正在网上寻找更好的例子,结果很短:-(

in.h @接口MyDataViewController:UIViewController{

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

成功的数据库检索:

while (sqlite3_step(statement) == SQLITE_ROW) {
            //I guess this one is wrong but I cant 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)]);

        }
从sqlitequeryn输出最后一个:

NSLog(@"%@", array);

您的输出是什么?您希望从中得到什么?您直接将NSString放入NSArray,对于静态NSArray,这可能会多次执行,也可能不会多次执行

如果您计划将多个字符串放入数组中,则应该有一个NSMutableArray,每次循环执行while时只需添加Object即可:

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

就像一个符咒。我如何设置这个问题来回答…?它说“我可以在2分钟内接受回答…”太好了!如果您一定要使用sqlite3查询,请不要忘记处理其中的错误消息。我更愿意推荐基本上适用于iPhone的任何db应用程序。Ray Wenderlich提供了一个不错的教程,他还提供了许多其他有用的教程:)thx,我会记得处理错误信息。到现在为止,我将使用带有受控查询的静态数据库,所以我希望这不会是一个骗局。
NSMutableArray *array = [[NSMutableArray alloc] init];
...code....
while (sqlite3_step(statement) == SQLITE_ROW) {
    [array addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}