开发者

mapView setRegion not being called from function

My header file:

@interface MapViewController : UIViewController <开发者_Go百科MKMapViewDelegate, NSFetchedResultsControllerDelegate>
{
    MKMapView *mapView;

    NSFetchedResultsController *fetchedResultsController;
    NSManagedObjectContext *managedObjectContext;
}

@property (nonatomic, retain) MKMapView *mapView;
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;

I am synthesizing as well in my .m file.

In my viewDidLoad function I have this (the view fades in via an animation in the parent controller) :

- (void)viewDidLoad
{
    [super viewDidLoad];

    mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
    mapView.mapType = MKMapTypeSatellite;
    mapView.delegate = self;
    self.view = mapView;
    [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
    self.view.alpha = 0.0;


    MKCoordinateRegion region;
    MKCoordinateSpan span;
    region.center.latitude = 42.764705;
    region.center.longitude = -94.047375;        
    span.latitudeDelta=.02;
    span.longitudeDelta=.02;
    region.span = span;
    [mapView setRegion:region animated:YES];
    NSLog(@"Change this1");
}

This works great.

I have another function:

- (void)setInitialMapView
{

    MKCoordinateRegion region;
    MKCoordinateSpan span;    
    region.center.latitude = 32.764705;
    region.center.longitude = -84.047375;        
    span.latitudeDelta=50.0;
    span.longitudeDelta=50.0;
    region.span = span;
    [mapView setRegion:region animated:YES];
    NSLog(@"Change this 2");
}

I call this second function when the animation is done.

This second function does NOT change the region of the map, but it does print to the log. So the function is being called.

What am I doing wrong here?


Not sure if this is the source of your problems, but it definitely seems like it could be, or could be contributing...

This line in your viewDidLoad is no good:

self.view = mapView;

I'd suggest adding the map view as a subview of self.view using addSubview (docs)

I have no idea what the repercussions of doing what you've done would be... but I have a feeling they wouldn't be good.

If you NEED to make your root view an MKMapView, I believe this should be done in the loadView method, as documented here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜