我正在做一些根本性的错误,但我正在网上寻找更好的例子,并且即将出现: - (
in .h @interface MyDataViewController:UIViewController {
NSArray *array;
}
@property (nonatomic, retain) NSArray *array;
in m
@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);
答案 0 :(得分:2)
您的输出是什么?您对此有何期待?您是直接将NSString放入NSArray中,对于静态NSArray,可能会或可能不会多次执行NSArray。
如果你打算在你的数组中放入几个字符串,你应该有一个NSMutableArray,每次循环时都只需要添加对象:
NSMutableArray *array = [[NSMutableArray alloc] init];
...code....
while (sqlite3_step(statement) == SQLITE_ROW) {
[array addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}