0

オブジェクトのプロパティがテーブルに表示される画面に、オブジェクトを含む NSArray を渡しています。これらの各オブジェクトには、緯度プロパティと経度プロパティが含まれています。ユーザーがセルを選択する機能を実装したいと思います (各セルは NSArray のオブジェクトを表します)。ユーザーは別の画面に移動し、マップ上のオブジェクトの位置を表す注釈を確認できます。およびユーザーを表す注釈。どうすればいいですか?私の RootViewController.m クラスからの関連コードは次のとおりです。

SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
        self.secondViewController = controller;
        [controller release];

        self.secondViewController.locationList = sortedLocations;

        [[self navigationController] pushViewController:controller animated:YES];

SecondViewController.m の関連コードは次のようになります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"locationcell";

LocationTableViewCell *cell = (LocationTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[LocationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

Location *location = [locationList objectAtIndex:indexPath.row];
cell.locationName.text = location.name; 
cell.locationAddress.text = location.address;
cell.locationDistance.text = location.distance;

return cell;
}

表示されるプロパティは名前、住所、距離ですが、場所オブジェクトには緯度と経度のプロパティも含まれていることに注意してください。MapViewController という新しい画面を作成する必要があることはわかっています。しかし、私が言ったように、画面上のテーブルから、場所オブジェクトとユーザーを示すマップに移動する場所が本当にわかりません。

4

2 に答える 2

0

MapView で新しい ViewController を作成し、緯度と経度の値を新しい ViewController に渡します。

View Controller を MyLocationMapViewController として作成したとします。

SecondViewController.m で以下を実装します

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Location *location = [locationList objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:[[MyLocationMapViewController alloc] initWithLocation:location] animated:YES];
}

MyLocationMapViewController.h で

  • (id)initWithLocation:(場所 *)場所;

MyLocationMapViewController.m 内

  • (id)initWithLocation:(Location *)location { *locationObj = location;

}

これで、locationObj を使用してマップ値を取得し、座標を MapView に表示できるようになりました。

于 2010-12-30T06:23:39.597 に答える
0

2番目のView ControllerにMapViewControllerオブジェクトを作成する

あなたのセカンドビューコントローラに以下のコードを書いてください

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MapViewController *mapView = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:[NSBundle mainBundle]];

    self. mapView = controller;
    [mapView release];
    
    
    self.mapView.latit = location.latitude;
    self.mapView.longi = location.longitude;
    [[self navigationController] pushViewController:controller animated:YES];
    

    }

緯度と経度を格納するために、MapViewController に latit と longi という 2 つの double 変数を作成します。

于 2010-12-30T06:23:58.987 に答える