我正在开发一个可以使用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:)];
答案 0 :(得分: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为nil。
答案 1 :(得分:0)
检查标识符,您必须正确使用sw_front
和sw_rear
进行搜寻。