Issue
I have an app with 3 views. I am using a tab bar controller to select the views.
I currently have the map set to zoom to the closest location that includes all the annotations. However, when I update the core data in view one, and then select tab 2 but the annotation pin remains the same. Even if I quit the app the pin color reamins the same (it changes color based on data state). the only way I can get it to update, is to zoom far in, then back out.
code I have tried:
[mapView release];
and
[mapView setNeedsDisplay];
and
[mapView removeAnnotation:tempAnnotation];
[mapView addAnnotation:tempAnnotation];
and
CLLocationCoordinate2D center = [mapView centerCoordinate];
[mapView setCenterCoordinate:center];
I even set the map set flyTo the coordinates 2 times, once zoomed far in, then again at 'normal' zoom level.
Is there a way to refresh the view on didFinishLoading
, etc?
Could I be placing one of these code snippets int he wrong place?
I am also releasing the passed data etc
is it just that the tab bar caches the page? is there a way to force a map refresh?
Thanks! (I am kind of a noob so if you can help, please be clear as to the steps to help me understand)
Robert
Solution
I am about to answer my own question with this as well:
I saw posts on how to reset the view, redraw the layer etc. I am fairly (not new) inexperienced with the language, so what I have done is a hack, but it works. I hope you use this if you have to, but find a better solution.
View Controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
mapView.region = MKCoordinateRegionMakeWithDistance([mapView centerCoordinate],2587600.0, 2587600.0);
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
mapView.region = MKCoordinateRegionMakeWithDistance([mapView centerCoordinate],5.0, 5.0);
}
So when the view leaves, well... view, then the map zooms really far in. When the view returns to view, the the data is reloaded and voila. Your mileage may vary, but this method works perfectly for what I need it to do.
And it is not a jarring effect at all. It is seamless. From a UI standpoint, nothing changes.
cheers! Robert
Answered By - roberthuttinger
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.