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

发布于 2024-09-03 07:13:15 字数 1627 浏览 2 评论 0原文

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

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

So far my program can display a database of custom annotation views. Eventually I want my program to be able to display extra information after a button on the annotation bubble is clicked. Each element in the database has a unique entry Number, so I thought it would be a good idea to add this entry number as a property of the custom annotation. The problem I am having is that after the button is clicked and the program switches to a new view I am unable to retrieve the entry number of the annotation I selected.
Below is the code that assigns the entry Number property to the annotation:

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];

When the button on an annotation is selected, this is the code that initializes the new view:

- (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];
   }

and lastly is my attempt at retrieving the entryNumber property from the new view so that I can compare it to the mines database and retrieve more information on the array element.

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 */
       }
  }

So how do I access this entry number property in this new view controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眸 2024-09-10 07:13:15

遇到同样的问题,您将不得不标记您的注释。看看这个,它肯定会对您有所帮助:

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

Had the same problem, you are gonna have to tag your annotations. Just check this out, it's definitely gonna help you:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文