I have a UITabBarController controlling a couple MKMapViews. How would I keep their state persistent with one another? I’ve tried setting up a singleton pattern, but they are still independent.
I have a UITabBarController controlling a couple MKMapViews . How would I keep their
Share
I see two possible solutions for your problem
You instantiate one (1x)
MKMapViewin a controller (maybe a singleton). Let’s say in yourAppDelegateyou have oneMKMapViewinstance.UIViewControllerinstance per Tab (so: many UIViewControllers but only one MKMapView in a controller.- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewControllerat your tabbar controller delegate.MKMapViewon the appearing UIViewController’s view.But here you will have the same content (Annotations, Regions, data at all)
You can synchronize many
MKMapView– mapView:regionWillChangeAnimated:, etc.) and synchronize the values to you other MKMapViews. You need to do that by Notifications (NSNotification) or by a controller.MKMapViewtoMKMapView.