我在做一些根本性的错误,但是我正在网上寻找更好的例子,并且很简短:-(
在.h中
@interface MyDataViewController:UIViewController {
NSArray *array;
}
@property (nonatomic, retain) NSArray *array;
在米
@synthesize array;
成功的dbretrieval:
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和addObject:
NSMutableArray *array = [[NSMutableArray alloc] init];
...code....
while (sqlite3_step(statement) == SQLITE_ROW) {
[array addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}
关于iphone - 同时在sqlite中填充数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5558663/