Search code examples
ioscocoa-touchuinavigationcontrollerecslidingviewcontroller

ECSlidingViewController Callback when sliding back to main view controller?


ECSlidingViewController inherits functionality from UINavigationController and I am currently trying to use

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

in my main view controller to act as a callback from back to the main view controller from the left view controller. The method is defined in the UINavigationDelegate class, so I had figured that it would be called on return to the main view controller, but alas, no call is ever made to it.

So, my question is simply regarding how to detect when the main view controller slides back into the screen, and calling some method afterwards.


Solution

  • The sliding view controller posts notifications when the views are switched. Generally it doesn't trigger delegate callbacks or view will/did method calls.

    Add yourself as an observer:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:... name:... object:nil];
    

    With the selector you want to be called and the name of the notification from ECSlidingViewController.h.