0

I have an iOS 7 app with a side hamburger menu and a main table view controller where I display content. Whenever the user selects an item in my side menu, I'm hiding the side menu and I want to reload data in the main view controller. My initial thought was to put my data refreshing code in my main view controller's viewWillAppear:

But when I set a breakpoint in viewWillAppear:, I get 2 calls when the view controller initially appears, one from UIViewController itself, and another from [ECSlidingViewController viewWillAppear:] where the following line seems to call my viewWillAppear: again

[self.topViewController beginAppearanceTransition:YES animated:animated];

On the other hand, when I show the left menu and then hide it, my view controller's viewWillAppear: is not called this time, so data is not refreshed in my case.

Did I miss something in my configuration somewhere? Is that a bug or a feature? How should I use it?

PS: I used to use IIViewDeckController and I had the exact same problem, so I switched to ECSlidingViewController because it said that "Your view controllers will receive the appropriate view life cycle and rotation methods at the right time.".

Neeku
  • 3,646
  • 8
  • 33
  • 43
Sebastien
  • 3,583
  • 4
  • 43
  • 82

1 Answers1

0

As a matter of fact, I managed to do what I wanted with another library: https://github.com/romaonthego/RESideMenu

I had to implement delegate methods in order to call lifecycle methods on my view controller when menu is shown or hidden:

- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController {
    [sideMenu.contentViewController viewWillDisappear:YES];
}

- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController {
    [sideMenu.contentViewController viewDidDisappear:YES];
}

- (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController {
    [sideMenu.contentViewController viewWillAppear:YES];
}

- (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController {
    [sideMenu.contentViewController viewDidAppear:YES];
}

And viewWillAppear is not called twice initially.

Sebastien
  • 3,583
  • 4
  • 43
  • 82
  • Just FYI, I think you shouldn't call those viewWill/Did methods directly. Call something like `beginAppearanceTransition:NO animated:YES` – danqing Sep 12 '14 at 15:45