Reputation: 11317
I am able to successfully show the user their current location on a MapView. However when I go to another view controller and come back to my mapview, I see a blue screen. Why?
This is my code:
- (void)viewWillAppear:(BOOL)animated {
MyManager * myManager = [MyManager sharedInstance];
//if coming back from another screen, lets load the coordinates
if (myManager.centerOfMap) {
NSLog(@"myManager.centerOfMap has a value:");
self.centerOfMap = myManager.centerOfMap;
}
CLLocationCoordinate2D zoomLocation;
zoomLocation = *(self.centerOfMap);
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];
[_mapView setRegion:adjustedRegion animated:YES];
}
Upvotes: 1
Views: 1183
Reputation: 33592
This bit sets off alarm bells:
CLLocationCoordinate2D zoomLocation;
zoomLocation = *(self.centerOfMap);
This presumably corresponds to
@property (nonatomic, assign) CLLocationCoordinate2D * centerOfMap;
Which means it's highly likely that it now points to a random bit of stack, which has since been overwritten. It is highly likely that the high-order word is between 0 and 0x4000000 (0 and a billion - most integers and memory addresses will be in this range), which means you end up with a double between (approximately) 0 and 2.
Get rid of the *
.
Upvotes: 0
Reputation: 8304
A blue screen is often a sign that you're point to (0,0) off the coast of Africa. Try printing out the coordinates of centerOfMap
Upvotes: 8
Reputation: 19834
At the point you come back, is the MKMapView allocated or does it show nil in the debugger?
Not sure? When you come back to your view controller, in the code go ahead and set a breakpoint and, in the console, type "po _mapView
". Look at the result.
If it is nil, you probably have to Alloc/Init it. What's probably going on is that ARC is automatically flushing out the MKMapView in order to save memory.
Just a question, are you presenting the new View Controller in a modal way using [yourMainViewController presentViewController:newViewController animated:YES]
?
Upvotes: 0