Domanda

I'm using Xcode 5 and the latest iOS SDK and I'm having a really hard time figuring out how to create custom annotations with a clickable button.

All I need is a custom annotation with a button, that is shown when the user taps a pin on my MKMapView. Following some tutorials, I managed to create a custom class that loads a .xib file, this already works. However, the problem is, that whenever I try to click a button placed on the annotation view, the pin gets deselected. I would love to be able to design my annotation in a .xib file and not create it 100% programmatically. Is there any way of doing so?

Thanks,

Niclas

È stato utile?

Soluzione

There is a great tutorial on maps on a site I used when I first got started into this section of iOS. It can be found here: http://www.raywenderlich.com/21365/introduction-to-mapkit-in-ios-6-tutorial ( Just an FYI, this is a great resource for learning more about iOS. )

Anyways, this paragraph should sound familiar (as to what you're after):

You’ve now made it so that in the callout when a pin is tapped on, there will be a button on the right hand side. When this is tapped, the mapView:annotationView:calloutAccessoryControlTapped: method is called. In this method, you grab the MyLocation object that this tap refers to and then launch the Maps app by calling the openInMapsWithLaunchOptions: method.

Just note that it is opening up the Maps app, but you can choose to do whatever you want really.

Later on, here are some other great links if you need them:

http://www.raywenderlich.com - This is where I started, recommend you do the same. Use their search box. They sell some privatized/self-published PDF books too if you like that.

http://www.cocoacontrols.com - You could probably find a control someone has already written with maps.. use the search, filter for iOS only.

http://www.nshipster.com - Great building block site

http://objc.io - Great site for getting into more low-level development.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top