SWRevealViewController is zero when adding a gesture recognizer

I am working on an application that will use the SWRevealViewController class. The application still works, since I can click on the left button of the panel to display the rear view controller, but when I add a gesture recognizer in my appearance controller, the SWRevealViewController is zero. I have no idea why this is so that any help would be appreciated.

//not nil here. SWRevealViewController *revealController = [self revealViewController]; //somehow it becomes nil on the very next line and from then on I can't hold the reference to it [self.navigationController.navigationBar addGestureRecognizer:[revealController panGestureRecognizer]]; UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)]; 
+6
source share
1 answer

Do you use storyboards?

If so, in your prepareForSegue: are you sure your segue has the SWRevealViewControllerSegue class, as shown below?

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue isKindOfClass: [SWRevealViewControllerSegue class]]) { SWRevealViewControllerSegue* rvcs = (SWRevealViewControllerSegue*) segue; SWRevealViewController* rvc = self.revealViewController; rvcs.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) { UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:dvc]; [rvc setFrontViewController:nc animated:YES]; }; } } 

I just solved it for my project, and self.revealViewController was null when I used the traditional [segue destinationViewController] method.

+1
source

Source: https://habr.com/ru/post/951150/


All Articles