2012-02-02 10 views
0

に応じて、テーブルビューにデータを送信するには、私は私のログでどのように以下の条件

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [dataArray count]; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    Person *temp = (Person *)[self.persons objectAtIndex:indexPath.row]; 
    cell.textLabel.text = temp.strName; 

    // Configure the cell... 

    return cell; 
} 



- (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); 
       //    NSLog(@" Id : %d",pID); 
       pName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; 
       NSLog(@" Name : %@",pName); 
       pAdd = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; 
       NSLog(@" Address : %@",pAdd); 
       pPh = sqlite3_column_int(compiledStatement, 3); 
       NSLog(@" PhoneNo : %d",pPh); 
       pCp = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)]; 
       NSLog(@" ContactPerson : %@",pCp); 
       pLat = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)]; 
       NSLog(@" Latitude : %@",pLat); 
       pLong = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)]; 
       NSLog(@" Longitude : %@",pLong); 



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

      } 

     } 
     sqlite3_finalize(compiledStatement); 
    } 
    sqlite3_close(database); 
} 



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

     Person *arr = [persons objectAtIndex:j]; 


     NSString *s = [[NSString alloc]initWithFormat:@"%@ %@ %@",arr.fLat,arr.fLong,arr.strName] ; 
     // 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 within 100 meters %@",resultArray); 
     } 
     else 
     { 
      NSLog(@"location %f, %f is not within %.0f meters of coord %f, %f", coord.latitude, coord.longitude, RADIUS, center.latitude, center.longitude);  

     } 
    } 

} 
} 

、私は緯度と経度は100メートル半径内にあるかどうかを確認するために使用していたコードです結果は期待通りにしか得られません。つまり、100メートル以内の緯度と経度と100メートル以内の緯度と経度が表示されますが、テーブルビューではすべての緯度と経度が表示されますが、 100メートル以内の緯度と経度のみを表示します。ここで私は間違いを犯しています。 ありがとうございます。あなたがdataArrayの数を取っているし、あなたが

Person *temp = (Person *)[self.persons objectAtIndex:indexPath.row]; 
cell.textLabel.text = temp.strName; 

をロードしているcellForRowAtIndexPath方法でそれが

cell.textLabel.text = [dataarray objectAtIndex:indexPath.row]; 

あるべきnumberOfRowsInSection方法で

+0

あなたのテーブルビューのコードを表示します。 – Sarah

+0

@Sarah私が更新したコードを確認してください。 – shasha

答えて

0

はこれを試してみてください。解決しなければ、教えてください。

+0

テーブルビューにまだすべての値が表示されています – shasha

+0

...データ配列の代わりにresultArrayを使用し、[resultArray addObject:coordString]の後にresultArrayを保持します。 – Sarah

+0

それは次の例外を投げる未知の例外 'NSRangeException'の理由でアプリケーションを終了しています:理由: '*** - [NSMutableArray objectAtIndex:]:境界3を超えるインデックス3 [0 .. 2]' numberOfRowsInSectionの – shasha

関連する問題