2013-10-29 59 views
0

我創建了一個類方法,但它不顯示數據。NSMutableDictionary的NSMutableArray不顯示數據

它顯示空值在控制檯當我做:

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

在「詞典」(它是的NSMutableDictionary的目的)示出了數據,但是當添加此對象插入到「陣列」(它是的NSMutableArray的對象),通過使用這樣的:

[array addObject:dict]; 

此行之後當我打印的值(使用NSLog(@"array data :- %@",[array objectAtIndex:0]);)陣列的它顯示我的「空」的值。

+(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) 

回答

1

你忘了創建一個數組

NSMutableArray *array = [NSMutableArray array]; 
+0

感謝喬治,它的工作原理。是的,這是一個愚蠢的錯誤。 – jitender

相關問題