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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With