John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 989 forks source link

Right view executing viewWillAppear & viewDidAppear as soon as I set rightViewController #257

Open dppeak opened 10 years ago

dppeak commented 10 years ago

I'm working on an app that only shows the rightViewController when the user has logged in. It uses storyboard to set the sw_rear, sw_front, and sw_right appropriately. Then in the viewDidLoad of the front controller I have the following code:

    if ([session isLoggedIn]) {
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];  
        if (self.revealViewController.rightViewController == nil) {
            [self.revealViewController setRightViewController:(UIViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"Right View"]];
        }
        self.revealMobilePayButtonItem = [[UIBarButtonItem alloc] initWithImage:([UIImage imageNamed: @"right_menu_btn.png"]) style:UIBarButtonItemStyleBordered target:self.revealViewController action:@selector(rightRevealToggle:)];
        [self.navigationItem setRightBarButtonItem:self.revealMobilePayButtonItem];
    } else {
        [session setSavedRightViewContoller:self.revealViewController.rightViewController];
        [self.revealViewController setRightViewController:nil];
    }

The problem is that as soon as I set rightViewController, the viewDidLoad, viewWillAppear, and viewDidAppear methods for the rightViewController are executed even though the right view is not yet revealed. Furthermore, when the user actually pans (or clicks right menu button) to display the right view, the viewWillAppear and viewDidAppear methods do not get called. This only happens the first time after setting the rightViewController.

We are supporting iOS 6 in this app, so we are using version 1.1.3 of the library.

Thanks, Dave

John-Lluch commented 10 years ago

Hi Dave, I can not tell for sure whether this is an issue on an older version. Can you reproduce this issue on the provided examples with the latest iOS?

Thanks,

jbhelm commented 9 years ago

Was there ever a resolution to this? I'm experiencing the same problem. The problem occurs when you call setRightViewController while the right view controller is /not/ revealed. The specific scenario is:

Note calling setRightViewController before the SWRevealViewController has actually been displayed on the screen seems to work fine.

This is with SWRevealViewController 2.3.0 on iPad running iOS 8 (tested up to 8.3). There are no storyboards or xib's, the user interface is entirely created in code. I only use SWRevealViewController on iPad, so I don't know if the same is true on iPhone.

John-Lluch commented 9 years ago

Hello jbhelm,

I just updated the class to v2.4.0. The class now removes the internal views from the view hierarchy when the rear or right views are concealed. This provides a different behaviour for calling the appearance methods. Please can you check whether it works as you expect now?

John

jbhelm commented 9 years ago

John --

Thank you for the /very/ quick response! I've downloaded 2.4.0 and a quick initial test shows that this version does indeed fix the issue, viewWillAppear/viewDidAppear are only called when the view is actually revealed.

Thank you!

Josh