mike
mike

Reputation: 1451

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:)];

Upvotes: 6

Views: 2025

Answers (2)

SinaMN75
SinaMN75

Reputation: 7621

check the identifiers, you have to use exactly, sw_front and sw_rear for segues.

Upvotes: 0

neverbendeasy
neverbendeasy

Reputation: 988

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.

Upvotes: 1

Related Questions