6

我正在开发一个使用 SWRevealViewController 类的应用程序。该应用程序到目前为止工作正常,因为我可以点击左侧栏按钮项以显示后视图控制器,但是当我在前视图控制器中添加手势识别器时,SWRevealViewController 为零。我不知道为什么会这样,任何帮助都将不胜感激。

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

2 回答 2

1

你在使用故事板吗?

如果是这样,在您的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];
        };
    } 
}

我刚刚为我的项目解决了这个问题,当我使用传统的 [segue destinationViewController] 方法时,self.revealViewController 为零。

于 2013-10-28T08:23:43.370 回答
0

检查标识符,你必须准确地使用,sw_front并且sw_rear用于segues。

于 2018-10-12T11:06:56.703 回答