これまでのところ、私のプログラムはカスタム注釈ビューのデータベースを表示できます。最終的には、注釈バブルのボタンがクリックされた後に、プログラムが追加情報を表示できるようにしたいと考えています。データベースの各要素には一意のエントリ番号があるため、このエントリ番号をカスタム アノテーションのプロパティとして追加することをお勧めします。私が抱えている問題は、ボタンをクリックしてプログラムが新しいビューに切り替わった後、選択した注釈のエントリ番号を取得できないことです。以下は、エントリ Number プロパティを注釈に割り当てるコードです。
for (id mine in mines)
{
workingCoordinate.latitude = [[mine latitudeInitial] doubleValue];
workingCoordinate.longitude = [[mine longitudeInitial] doubleValue];
iProspectAnnotation *tempMine = [[iProspectAnnotation alloc] initWithCoordinate:workingCoordinate];
[tempMine setTitle:[mine mineName]];
[tempMine setAnnotationEntryNumber:[mine entryNumber]];
}
[mines dealloc];
注釈のボタンが選択されている場合、これは新しいビューを初期化するコードです。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
mineInformationController *controller = [[mineInformationController alloc] initWithNibName:@"mineInformationController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}
最後に、新しいビューから entryNumber プロパティを取得して、鉱山データベースと比較し、配列要素に関する詳細情報を取得できるようにします。
iProspectFresno_LiteAppDelegate *appDelegate = (iProspectFresno_LiteAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray* mines = [[NSMutableArray alloc] initWithArray:(NSMutableArray *)appDelegate.mines];
for(id mine in mines)
{
if ([[mine entryNumber] isEqualToNumber: /*the entry Number of the selected annotation*/])
{
/* display the information in the mine object */
}
}
では、この新しいビュー コントローラーでこのエントリ番号プロパティにアクセスするにはどうすればよいでしょうか?