iphone - 同时在sqlite中填充数组

标签 iphone arrays xcode sqlite populate

我在做一些根本性的错误,但是我正在网上寻找更好的例子,并且很简短:-(

在.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/

相关文章:

iphone - 在两个不同点之间画线

javascript - 如何创建具有某些数组值的对象而不保存对数组的引用?

Javascript 创建类别超链接数组

xcode - Xcode项目中缺少应用程序沙箱功能

xcode - 从自定义单元格中调用 TableViewController 中的方法

iphone - 覆盖 Titanium 中导航栏的始终位于顶部的属性

ios - UIScrollView 中的多个 UITableView(如 Etsy 应用程序)

iphone - 在 iOS 中使用 mime 类型或 UTI 类型的内置图标

C++ 求数组中数字的平均值

objective-c - 如何自动生成从 XSD 到 Objective C IOS 的类?