gpt4 book ai didi

ios - NSMutableDictionary 的 NSMutableArray 不显示数据

转载 作者:行者123 更新时间:2023-11-29 03:31:55 24 4
gpt4 key购买 nike

我创建了一个类方法,但它没有显示数据。

当我这样做时,它在控制台中显示空值:

NSLog(@"full and array data :- %@",[array ObjectAtIndex:0]);

“字典”(它是 NSMutableDictionary 的一个对象)显示了数据,但是当我使用这个将这个对象添加到“数组”(它是 NSMutableArray 的一个对象)时:

[array addObject:dict];

在这一行之后,当我打印数组的值(使用 NSLog(@"array data :- %@",[array objectAtIndex:0] );)时,它显示了 'null'值(value)。

+(NSMutableArray *)showAllDetail:(NSString *)query{    
sqlite3 *stmnt;
NSMutableArray *array;
NSString *databasepath=[database getDatabasePath];
if (sqlite3_open([databasepath UTF8String], &stmnt)) {
NSLog(@"database not open......");
}
else{

const char *queryStmt=[query UTF8String];
sqlite3_stmt *stmt;

if (sqlite3_prepare_v2(stmnt, queryStmt, -1, &stmt, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt)==SQLITE_ROW) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
const char *text;


text=(char *)sqlite3_column_text(stmt,1);
//NSLog(@"text :- %s",text);
if (text!=NULL) {
[dictionary setObject:[NSString stringWithUTF8String:text] forKey:@"id"];

//NSLog(@"dictionary with id : - %@",dictionary);
}

text=(char *)sqlite3_column_text(stmt,2);
if (text!=NULL) {
[dictionary setObject:[NSString stringWithUTF8String:text] forKey:@"name"];
// NSLog(@"dictionary with name : - %@",dictionary);
}

text=(char *)sqlite3_column_text(stmt,3);
if (text!=NULL) {
[dictionary setObject:[NSString stringWithUTF8String:text] forKey:@"dob"];
// NSLog(@"dictionary with dob: - %@",dictionary);
}


NSLog(@"in the dic :- %s",text);
NSLog(@"dictionary data :- %@",dictionary);
//------------------------------------------------
//---------this show the result data dictionary --
//------------------------------------------------
[array addObject:dict];
NSLog(@"array data :- %@",[array objectAtIndex:0] );
//------------------------------------------------------------
//---------this show the result :- "full and array data :- null"
//---------------------------------------------------------------
dict=nil;
}
}
sqlite3_finalize(stmt);
if ([array count]>0) {
return array ;
}
else
return nil;
}

return nil;
}

我的输出是:-

2013-10-29 17:30:32.644 myCRUD[1231:a0b] dictionary data :- {
id = 1;
name = naresh;
dob = "10/10/1990";

}
2013-10-29 17:30:32.645 myCRUD[1231:a0b] array data :- (null)

最佳答案

您忘记创建数组

NSMutableArray *array = [NSMutableArray array];

关于ios - NSMutableDictionary 的 NSMutableArray 不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19657791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com