简体   繁体   中英

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

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.

检查标识符,你必须准确使用, sw_frontsw_rear用于segues。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM