对象数量 (3) 不等于键数量 (8)
好的,所以问题来自于尝试从 sqlite DB 中提取数据并将其放入数组中以进行滚动视图显示。我使用 FM 数据库库连接到 sql 数据库
代码如下:
NSMutableArray *data = [[NSMutableArray alloc] init];
FMResultSet *result = [[[StorageTank sharedStorageTank] DB]
executeQuery:@"SELECT * FROM table"];
while([result next])
{
NSArray *values = [[NSArray alloc] initWithObjects:
[[NSNumber alloc] initWithInt:[result intForColumn:@"id"]],
[[NSNumber alloc] initWithInt:[result intForColumn:@"count"]],
[[NSNumber alloc] initWithInt:[result intForColumn:@"required"]],
[result stringForColumn:@"image_portrait"],
[result stringForColumn:@"image_landscape"],
[[NSNumber alloc] initWithInt:[result intForColumn:@"end_date"]],
[[NSNumber alloc] initWithInt:[result intForColumn:@"active"]],
[result stringForColumn:@"merchant"], nil];
NSLog(@"%@", values);
NSArray *keys = [[NSArray alloc] initWithObjects: @"id",@"count",@"required",
@"image_portrait",@"image_landscape",
@"end_date",@"active",@"merchant",nil];
NSLog(@"%@", keys);
NSDictionary *row = [[NSDictionary alloc] initWithObjects: values forKeys: keys];
[data addObject: row];
}
NSArray *resultArray = [[NSArray alloc] init];
resultArray = data;
因此,显然从我测试过的代码来看,确保值计数等于键计数...但我仍然收到此错误:
“终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“-[__NSPlaceholderDictionary initWithObjects:forKeys:]:对象数量(3)不等于键数量(8)'”
我我一生都无法理解为什么当我打印出值数组时看到 8 个值时计数会有所不同...这应该与我的 8 个键匹配?他们是正确的吗?
任何帮助/指导将不胜感激!
谢谢,
Ok, so the issue is coming from trying to pull data from a sqlite DB and place it in an array for a scroll view display. Im using FM Database library to connect to sql database
The code is as follows:
NSMutableArray *data = [[NSMutableArray alloc] init];
FMResultSet *result = [[[StorageTank sharedStorageTank] DB]
executeQuery:@"SELECT * FROM table"];
while([result next])
{
NSArray *values = [[NSArray alloc] initWithObjects:
[[NSNumber alloc] initWithInt:[result intForColumn:@"id"]],
[[NSNumber alloc] initWithInt:[result intForColumn:@"count"]],
[[NSNumber alloc] initWithInt:[result intForColumn:@"required"]],
[result stringForColumn:@"image_portrait"],
[result stringForColumn:@"image_landscape"],
[[NSNumber alloc] initWithInt:[result intForColumn:@"end_date"]],
[[NSNumber alloc] initWithInt:[result intForColumn:@"active"]],
[result stringForColumn:@"merchant"], nil];
NSLog(@"%@", values);
NSArray *keys = [[NSArray alloc] initWithObjects: @"id",@"count",@"required",
@"image_portrait",@"image_landscape",
@"end_date",@"active",@"merchant",nil];
NSLog(@"%@", keys);
NSDictionary *row = [[NSDictionary alloc] initWithObjects: values forKeys: keys];
[data addObject: row];
}
NSArray *resultArray = [[NSArray alloc] init];
resultArray = data;
So, obviously from the code i've tested to make sure the values count is equal to the keys count... yet Im still getting this error:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithObjects:forKeys:]: number of objects (3) not equal to number of keys (8)'"
I can't understand for the life of me why the count would differ if when I print out the values array I see 8 values... which should match my 8 keys? and they are correct?
Any help/direction would be greatly appreciated!
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的值数组中的第四项是:
返回 nil 吗?该值告诉 -initWithObjects 列表已完成。
Is the fourth item in your values array:
returning
nil
? That's the value that tells -initWithObjects that the list is done.