junyu-w
junyu-w

Reputation: 101

self.revealViewController becomes nil and SWRevealViewController Menu not showing after segue back to SWRevelViewController from a certain VC

I'm using the SWRevelViewController framework and met this problem while coding. Basically here's the list of my VCs and their classes: http://mnch.in/ubyB/3g4uqSwl (picture of my story board)

The problem is when user logged in in UIVC_2, it goes back to SWRevelVC using the segue marked in blue. However, when the viewDidLoad method in UITableVC gets called

SWRevealViewController *revealViewController = self.revealViewController;
NSLog(@"%@", [revealViewController description]);
if (revealViewController) {
    NSLog(@"hey");
    [self.sidebarButton setTarget: self.revealViewController];
    [self.sidebarButton setAction: @selector( revealToggle: )];
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}

self.revealViewController becomes nil and therefore the sidebar stops working since it never gets into the if statement and set the target for sidebar button.

However, if I first logged in user, and close the app, and then build and run the app again, UITableVC gets showed directly (UIVC_1, UIVC_2 won't pop up),and in its viewDidLoad method, self.revealViewController is not nil, therefore sidebar works in this case.

Can anyone explain why this happened and how should I fix it so that when I segued from UIVC_2 to SWRevealVC, self.revealViewController won't be nil? I've been thinking about this for a long time and still didn't get it. Thanks a lot!

edit: Here is a similar question that is not answered either: Swift SWRevealViewController Menu not showing after segue back to certain page. My case suggested that even when you segue all the way back to SWRevealViewController, self.revealViewController is still not initialized

Upvotes: 1

Views: 1774

Answers (1)

junyu-w
junyu-w

Reputation: 101

Actually nevermind I was being stupid, this actually works, the mistake I made is I changed the segue from UIVC_2 to SWRevelVC, but I kept testing using another VC (let's call it UIVC_3) and UIVC_3's segue hasn't been linked to SWRevealVC but instead the navigation controller...

Upvotes: 1

Related Questions