Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWRevealViewController is nil when adding gesture recognizer

I'm working on an app that will make use of the SWRevealViewController class. The app works so far, in that I'm able to tap the left bar button item to bring out the rear view controller, but when I add a gesture recognizer in my front view controller, the SWRevealViewController is nil. I have no clue why this is so 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:)];
like image 383
mike Avatar asked Aug 06 '13 17:08

mike


1 Answers

Are you using storyboards?

If so, in your prepareForSegue:, are you making sure your segue is of the SWRevealViewControllerSegue class, like 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 this for my project and self.revealViewController was nil when I was using the traditional [segue destinationViewController] method.

like image 52
neverbendeasy Avatar answered Sep 20 '22 20:09

neverbendeasy