Iphone – popover segue with no anchor, MKMapView

iphoneuipopovercontrolleruistoryboard

I'm trying to present a popover over a pin I added to a MKMapView. I added a UIViewController to my storyboard, and dragged a segue from the MKMapView in one view controller to the viewController I want to show in my popover and selected popover. I get the error:

Popover segue with no anchor

In IB, I see "Drag to select an anchor", but when I try dragging it anywhere within the first viewController that has the MKMapView in it, nothing gets selected. I'm not sure where to go from here and if popover's from a view that is created dynamically can be used to present a popover with Storyboards. I know I can do it in code, but then I have to copy and paste my setters in prepareForSegue:. Thoughts? Thanks.

Best Answer

You need to make a custom annotation view. This will look like a popover view but it is actually different. A great tutorial on this can be found here: http://www.raywenderlich.com/30001/overlay-images-and-overlay-views-with-mapkit-tutorial

Essentially, you need to go NEW->NEW FILE-> the first option on the top left for OBJECTIVE C CLASS-> Name it whatever you want, I recommend CustomAnnotationView, and make it part of NSObject (rather than the default UIViewController)->follow the instructions on the above listed tutorial. If that tutorial does not work for you then you can search "custom map annotation" and many others will pop up. Apple even has a couple good (though outdated) sample projects which due this, such as a weather app and a callouts app with callouts for three locations in San Francisco.

Related Topic