Search code examples
iosmkmapviewmodalviewcontrolleruistoryboardsegue

Changing MKMapType using modal segue with partial curl


I am writing an app where I have a mapview displayed. Now I want to give the user the option to change the MKMapType from standard to hybrid.

In oder to do that I created a segue to another view controller containing a switch to set the Map Type. The transition is modal using a partial curl. To access the value of the switch, I introduced a BOOL which is called fotoMode in AppDelegate. If this variable is set to YES (and if the switch is set to ON) then I'd like to redraw the map.

- (IBAction) FotoModusSwitchChanged:(UISwitch *)sender 
{
 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];    
if(sender.isOn)
 {
    appDelegate.fotoMode=YES;
 }
 else 
 {
    appDelegate.fotoMode=NO;
 }
}

I have included the following lines of code in VieWillAppear, ViewDidAppear, ViewDidLoad, ViewWillLayoutSubviews of the view controller for the Map View but it does not work:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];    
if (appDelegate.fotoMode) {
    [self.MapOutlet setMapType:MKMapTypeHybrid];
}
else
{
    [self.MapOutlet setMapType:MKMapTypeStandard];
}

Any idea what I am doing wrong? Thanks.

PS: Setting the MKMapType manually to Hybrid or Standard works...


Solution

  • your code seems right to me but I think you're having problem with declaration of the "fotoMode".

    Make sure that under your Appdelegate.h file you define your BOOL

    @property(nonatomic,assign) BOOL fotoMode;

    if you don't declare your BOOL right then you wont' be able to set and get the right value.

    Hope helps...