到目前为止,我的程序可以显示自定义注释视图的数据库。最终,我希望我的程序能够在单击注释气泡上的按钮后显示额外的信息。数据库中的每个元素都有一个唯一的条目编号,因此我认为将此条目编号添加为自定义注释的属性是个好主意。我遇到的问题是,在单击按钮并且程序切换到新视图后,我无法检索我选择的注释的条目号。下面是将条目 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 属性,以便我可以将其与 mines 数据库进行比较并检索有关数组元素的更多信息。
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 */
}
}
那么如何在这个新的视图控制器中访问这个条目号属性呢?