Search code examples
iosobjective-cdelegatesskmaps

How can I reset navigation delegate, after switching between ViewControllers


Navigation starts, all the delegate methods are set and everything works as intended.

But if a user switches to another ViewController, while navigation is still on, and returns to the navigation view controller, something happens with the navigation delegate, and all navigation delegate methods are unresponsive.

I of course tried setting them again

[SKRoutingService sharedInstance].navigationDelegate = self;

even tried setting them first to nil and then setting them to self again

[SKRoutingService sharedInstance].navigationDelegate = nil;
[SKRoutingService sharedInstance].navigationDelegate = self;

But it doesn't work.

So my questions are:

Can I even set the navigation delegate, after the navigation has started?

What could be the general cause of the ViewController "loosing" delegate?

P.S. I tried not setting delegates to another view controller, when I switch between them (even though I have a map on that other one as well, but didn't work out). As soon as I change my NavigationView controller by segueing to another one, navigationDelegate methods become unresponsive.


Solution

  • Ok, apparently It had nothing to do with the delegates but the fact that I didn't know I had to start navigation again, once I got returned to the Screen where navigation was on.

    As I would transfer to the second screen, where I had another map, I could see that the user cursor was moving, so I assumed that navigation was still on, as the map is a singleton.

    But in the end, starting navigation again with solved the issue

    SKNavigationSettings* navSettings = [SKNavigationSettings navigationSettings];
    
        navSettings.navigationType=SKNavigationTypeSimulation;
        //navSettings.navigationType = SKNavigationTypeReal;
    
        navSettings.distanceFormat=SKDistanceFormatMilesFeet;
        navSettings.zoomLevelConfigurations = nil;
        [SKRoutingService sharedInstance].mapView.settings.displayMode = SKMapDisplayMode3D;
    
        [[SKRoutingService sharedInstance]startNavigationWithSettings:navSettings];