开发者

MKMapView not updating when i call setCoordinate

开发者 https://www.devze.com 2023-03-10 03:01 出处:网络
This is my second question today and the first was an incredibly stupid question so I\'m fully expecting this one to be as well.

This is my second question today and the first was an incredibly stupid question so I'm fully expecting this one to be as well.

I have a view with an embedd开发者_StackOverflowed MKMapView.

I want to some how be able to get at this MKMapView? Can I connect it up someway in the xib file? Or failing that ... can I just extract it directly from the parent view controller?

I want to do things like use setCoordinates but I can't figure out how to get at the MKMapView instance to call the function on.

How do I get at the MKMapView object.


In the place that you want to get at it from, set up an outlet. In the .h file, declare a mapview property

MKMapView *mapView;

then declare its property with an IBOutlet

@property (nonatomic, retain) IBOutlet MKMapView *mapView;

You should be able to control-drag from File's Owner in your IB file to the mapview in your view to make a connection. Select "mapView" in the popup that appears and your file will be connected to the mapview object. Then you can use the property mapView in your .m file to set things on the mapview.

[self.mapView setCoordinates:myCoordinates];

Make sure you import your framework properly too.


It sounds like you are using Interface Builder to display this MKMapView. To be able to get the instance of MKMapView that is onscreen, follow these steps.

1) Open the .h file of the view controller for the view that contains the MKMapView.

2) In the instance variables section, add the line

IBOutlet MKMapView *mapView;

3) Go back to interface builder, and click on the map view you added to the XIB

4) Press Control, and while holding it down click and drag on the map view. This should make a blue line follow your mouse from the spot on the map view.

5) Drag the blue line over to the list of objects in your XIB. For a normal view controller xib, this list should be something like File's Owner. First Responder, and View. Unclick on the 'Files Owner' object.

6) This should bring up a list of connections. Click on the one that says 'mapView'

7) Profit! Now inside of your view controller, you can access the instance of the map view by using the mapView instance variable.


Make sure you set your delegate methods for the MKMapView and the methods should fire on your delegate class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号