ios - NSMutableDictionary 的 NSMutableArray 不显示数据

标签 ios objective-c nsmutablearray nsmutabledictionary

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

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

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/

相关文章:

ios - Firebase 动态链接未打开应用程序 iOS

ios - Xcode 单元测试 - 无法添加新测试,因为它没有运行

ios - 从另一个类实例更新一个类中定义的 UIProgressView

ios - 我们可以在 Facebook SDK 3.1 中使用 DeprecatedHeaders 多长时间?

ios - AVCaptureVideoDataOutput 和图像在屏幕上的显示大小

objective-c - 将静态库导入自定义通用框架

iphone - 将新对象添加到 NSMutableArray

objective-c - 如何避免 NSArray 中的重复元素并在 TableView 单元格中打印

objective-c - 将 NSMutableArray 与 NSTableView (Cocoa) 一起使用时出现问题

ios - 无法转换类型的值 - Swift