在 sqlite 中填充数组
我正在做一些根本性的错误,但我正在网上寻找更好的例子,并且
在 .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);
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 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的产出是什么?您对此有何期望?您直接将 NSString 放入 NSArray 中,对于静态 NSArray 可能会或可能不会多次执行此操作。
如果您打算将多个字符串放入数组中,则应该有一个 NSMutableArray 并在每次循环 while 时简单地 addObject :
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: