2012-02-01 22 views
0

は、以下の私が使用していたコード、のNSLogためを別の方法である方法から値を読み取る方法

- (void) readDataFromDatabase{ 

    sqlite3 *database; 
    persons = [[NSMutableArray alloc]init]; 

    if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){ 

     const char *sqlStatement = "select * from sdata"; 
     sqlite3_stmt *compiledStatement; 
     if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK){ 

      while (sqlite3_step(compiledStatement) == SQLITE_ROW) { 

       pID = sqlite3_column_int(compiledStatement, 0); 
       pName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; 
       pAdd = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; 
       pPh = sqlite3_column_int(compiledStatement, 3); 
       pCp = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)]; 
       pLat = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)]; 
       pLong = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)]; 

       Person *temp = [[Person alloc]initWithID:pID name:pName address:pAdd phone:pPh contactperson:pCp fLat:pLat fLong:pLong]; 


       [persons addObject:temp]; 
       NSLog(@"Inside Persons : %@",persons); 
       [temp release]; 

      } 

     } 
     sqlite3_finalize(compiledStatement); 
    } 
    sqlite3_close(database); 
} 
For the NSLog in NSLog(@"Inside Persons : %@",persons);i get the output as Inside Persons : ("<Person: 0x4c26ae0>" 

- (void)startTest 
{ 

    for(int j=0;j<[persons count];j++){ 

     Person *arr = [persons objectAtIndex:j]; 


     NSString *s = [[NSString alloc]initWithFormat:@"%f",arr.fLat] ; 
     NSLog(@" data in array : %@", s); 
    } 


#define COORDS_COUNT 1 
#define RADIUS  100.0f 

    CLLocationCoordinate2D coords[COORDS_COUNT] = { 
     CLLocationCoordinate2DMake([arr.fLat floatValue], [arr.fLong floatValue ]), 


    }; 

    CLLocationCoordinate2D center = CLLocationCoordinate2DMake([lat floatValue], [longt floatValue]); 
    CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:center radius:RADIUS identifier:@"Banashankari"]; 



    for (int i = 0; i < COORDS_COUNT; i++) 
    { 
     CLLocationCoordinate2D coord = coords[i]; 

     NSString *coordString = [NSString stringWithFormat:@"%f,%f",coord.latitude, coord.longitude]; 
     [dataArray addObject:coordString]; 

     if ([region containsCoordinate:coord]) 
     { 
      NSLog(@"location %f, %f is within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude); 
      [resultArray addObject:coordString]; 
      NSLog(@"data in resultArray %@",resultArray); 
     } 
     else 
     { 
      NSLog(@"location %f, %f is not within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude);  

     } 
    } 
} 

(@「アレイ内のデータ:%の@」、単数または複数)です。私は配列のデータとして出力を取得しています:0.000000、しかし、期待値は12.920684、77.560033です。 startTestメソッドで期待値を取得する方法。ここで私は間違いを犯しています。 ありがとうございました。

答えて

1

nsmutablearray人の@property(非アトミック、リテンション)を使用しますか?また、配列にフェッチされているかどうかを調べてみてください。配列に値が格納された後に、retainを使用します。

+0

私はNSMutablearray人のために@property(非原子、保持)を使用しました。 – shasha

+0

と[人addObject:temp]の後に可変配列を保持するのはどうですか?また、値が配列にフェッチされているかどうかをチェックしようとしますか? – Sarah

+0

また、[人のaddObject:temp]の後に可変配列を保持しようとしました。値を取得していない – shasha

関連する問題