2010-12-30 10 views
0

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

私の関連するコードは次のようになります。

- (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という新しいスクリーンを作成しなければならないことを知っています。しかし、私が言ったように、私は本当に画面上のテーブルから、場所オブジェクトとユーザーを示すマップに行くか分からない。

答えて

0

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

ビューコントローラを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で

    :(場所*)位置{ * locationObj =場所。

}

今、あなたはマップの値を取得するためlocationObjを使用してのMapViewの座標を表示することができます。

+0

ありがとうを格納するMapViewControllerにlatitとlongiと呼ばれる2つの二重変数を作成します。あなたにフォローアップの質問がありました。 * locationObjはどのタイプですか?これは私を捨てている。あなたの時間と忍耐力に感謝します。 – syedfa

+0

MyLocationMapViewController.hファイルにあります。場所の作成* locationObj。 Location変数に@propertyを設定します。今はっきりしたいと思っています。 – Swapna

+0

ご返信ありがとうございます。私は別のフォローアップの質問をしました。 MyLocationMapViewControllerクラスを作成したとき、関連する.xibファイルがxcodeによって作成されていませんでした。独自の.xibファイルを作成する場合、MyLocationMapViewControllerクラスにどのようにリンクするのですか?私はお詫びしますが、私はiPhoneの開発には非常に新しいです。あなたの助けをもう一度ありがとう。 – syedfa

0

あなたsecondviewコントローラ

  • (ボイド)のtableViewに以下のコードを書くsecondviewコントローラでMapViewControllerオブジェクトの作成:(のUITableView *)のtableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MapViewController * [MapViewController alloc] initWithNibName:@ "MapViewController"バンドル:[NSBundle mainBundle]];

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

    }

あなたの返事のための緯度と経度

+0

私の質問に答える時間をとってくれてありがとう! – syedfa

関連する問題