Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blast12345

macrumors newbie
Original poster
Jul 11, 2012
7
0
In this project, there are two map pins/annotations. When one is clicked on, a popup (separate xib file) pops up and will eventually display information (UILabels) about the pin you clicked on.

The issue I am having lies in the fact that I have multiple pins. I need to make my text in the xib file change based upon which pin was clicked on.

I was guessing that I could make this work using an if/else statement (If pinA is clicked, the display this information). Unfortunately, I have no idea what type of code is needed to perform this operation (if such code actually exists).

Another iOS programmer at my work suggested something involving tags, but I don't have enough experience with iOS/XCode to plop out the code based on his explanation (and I don't want take up too much of his time with this; he has his own work to do).

I have attached a file so that anyone can view my work as a whole. If you have any pointers, I would much appreciate it.
 

Attachments

  • MapTestFinal copy 4 - Assist.zip
    56.8 KB · Views: 66

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
I have no experience with pins, but I'd say that you'll probably have them set up to invoke something like
Code:
- onTap:(Pin*) sender

You can then query sender to find out more data about it. As an example of how you could use this you could do:

Code:
switch (sender.tag) { ...

I don't know where the pins are created though. Did you set them up in a xib file? If so, you can check the identity inspector (right side of the window when you're editing xib files) and set the tag there. Or right after it's created in code, set its tag.

Just my thoughts.

And for in the future, don't upload .zips. I didn't download it, and I doubt anyone else will either. It's too much effort on our part to download your code, open it up, try to find the relevant sections, and then help you without just telling you the answer.

Instead, put the effort in to find the relevant parts that we'd be looking for if we did have the time to download your project, and post them directly to the forum. If it's a question relating to graphics, include a screenshot or something. If it's all code (most programming questions are,) then just copy and paste the relevant portion of code and remember to surrounding it was (code) and (/code) tags, with the ()'s replaced with their [] counterparts.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I have no experience with pins, but I'd say that you'll probably have them set up to invoke something like
Code:
- onTap:(Pin*) sender

MKMapView can use a delegate (MKMapViewDelegate) that has a mapView:annotationView:calloutAccessoryControlTapped: delegate method. This sounds like the place to me to handle the presentation of the different views.

Side Note: ArtOfWarfare, if you have no experience with pins, IMHO, you don't need to be trying to address this part of the issue. And your answers could lead the OP astray and cause them unneeded frustration. I know you're eager to provide help, but consider how much help you are providing with a "shot-in-the-dark" answer.

Another iOS programmer at my work suggested something involving tags, but I don't have enough experience with iOS/XCode to plop out the code based on his explanation (and I don't want take up too much of his time with this; he has his own work to do).

If you have mapView:annotationView:calloutAccessoryControlTapped: implemented, provide us the code for that. Also, take a look at MKAnnotationView and see if there's a property in it (or within an ancestor class of it) that you can use to differentiate. I will say that using UIView's tag property is a pretty common way to go about this, and that's what I would recommend.
 

TheWatchfulOne

macrumors 6502a
Jun 19, 2009
838
972
Blast, can we have a little further explanation of what you are trying to do?

Are you presenting a call out over the pin before presenting the view?

Or are you skipping the call out and going straight to the view?

Deja gave you a good method to try but it sounds like you need to present a call out bubble with at least one accessory button in order to be able to use it.

Here's another method you might try:

Code:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

This will allow you to get a reference to a selected annotation without presenting a call out bubble.

I have been working quite a bit with MapKit in my current project, so I do have some experience with it and I'll be happy to try to help you.
 
Last edited by a moderator:

Blast12345

macrumors newbie
Original poster
Jul 11, 2012
7
0
I got it working.

Code:
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    NSString*locationTitle = [view.annotation title];


----bunch of code for my progams popup ui here----

            [_textOne setText:locationTitle];
}

The NSString*locationTitle grabs information from my map-pins information (coded in an earlier event).

I appreciate the code TheWatchfulOne. When I would close my xib popup and then click on the callout bubble, my app would crash. This answers a question before I even had to ask. Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.