简体   繁体   English

添加手势识别器时,SWRevealViewController为零

[英]SWRevealViewController is nil when adding gesture recognizer

I'm working on an app that will make use of the SWRevealViewController class. 我正在开发一个将使用SWRevealViewController类的应用程序。 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. 该应用程序到目前为止工作,我可以点击左栏按钮项目带出后视图控制器,但当我在前视图控制器中添加手势识别器时,SWRevealViewController是零。 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? 如果是这样,在prepareForSegue:你确定你的segue属于SWRevealViewControllerSegue类,如下所示吗?

- (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. 我刚刚为我的项目解决了这个问题,当我使用传统的[segue destinationViewController]方法时,self.revealViewController是nil。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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