如何让程序知道选择了哪个注释并能够访问它的属性?

时间:2010-05-29 18:58:06

标签: iphone sdk mkmapview mkannotation viewcontroller

到目前为止,我的程序可以显示自定义注释视图的数据库。最后,我希望我的程序能够在单击注释气泡上的按钮后显示额外信息。数据库中的每个元素都有一个唯一的条目号,所以我认为将此条目号添加为自定义注释的属性是个好主意。我遇到的问题是,在单击按钮并且程序切换到新视图后,我无法检索我选择的注释的条目编号。 下面是将条目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 */
       }
  }

那么如何在这个新的视图控制器中访问此条目编号属性?

1 个答案:

答案 0 :(得分:0)

遇到同样的问题,你必须标记你的注释。看看这个,它肯定会帮助你:

http://www.everydayone.com/2009/08/mapkit_annotations/