Search code examples
iosecslidingviewcontroller

Is there a way for the Top View Controller in ECSlidingViewController to know when the sidebar menu has been dismissed?


Is there a way for the Top View Controller in ECSlidingViewController to know when the sidebar menu has been dismissed, or when it is about to become the focus? i.e. a sort of viewWillAppear equivalent for ECSlidingViewController. I have a refreshcontrol in my top view controller that starts misbehaving after the sidebar is shown, so I am trying to figure out where I can call endRefreshing on the refreshControl so that the wierdness goes away. Putting it in viewWillAppear doesn't work. Thanks!


Solution

  • Since ECSlidingViewController v2.0 does not have notifications, I was able to solve this in the following way. In the sidebar menu, in ViewWillDisappear I call a new category method on UIViewController called "willGetFocus." Whenever my topViewController needs to know when it's about to get focus I override willGetFocus in that view Controller like so:

    In sidebar menu:

     -(void) viewWillDisappear:(BOOL)animated
     {
         [super viewWillDisappear:animated];
         UINavigationController* topViewController =    
            ((UINavigationController*)self.slidingViewController.topViewController);
         [topViewController.visibleViewController willGetFocus];
     }
    

    In Top View Controller:

    -(void) willGetFocus {
    
        [self.refreshControl endRefreshing];
    }
    

    New Category:

    @interface UIViewController (KnowsFocus)
    
    -(void) willGetFocus;
    
    @end
    
    @implementation UIViewController (KnowsFocus)
    
    -(void) willGetFocus {
    
    }
    @end