我创建了一个类方法,但它没有显示数据。
当我这样做时,它在控制台中显示空值:
NSLog(@"full and array data :- %@",[array ObjectAtIndex:0]);
'dictionary'(它是NSMutableDictionary的一个对象)显示了数据,但是当我将这个对象添加到'array'(它是NSMutableArray的一个对象)时,使用它:
[array addObject:dict];
在此行之后,当我打印数组的值(使用NSLog(@"array data :- %@",[array objectAtIndex:0] );
)时,它会显示“null”值。
+(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)
答案 0 :(得分:1)
你忘了创建一个数组
NSMutableArray *array = [NSMutableArray array];