在 sqlite 中填充数组

发布于 2024-10-30 18:24:43 字数 886 浏览 0 评论 0原文

我正在做一些根本性的错误,但我正在网上寻找更好的例子,并且

在 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-11-06 18:24:43

您的产出是什么?您对此有何期望?您直接将 NSString 放入 NSArray 中,对于静态 NSArray 可能会或可能不会多次执行此操作。

如果您打算将多个字符串放入数组中,则应该有一个 NSMutableArray 并在每次循环 while 时简单地 addObject :

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

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)]];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文