Priyanka
Priyanka

Reputation: 513

self.revealViewController.panGestureRecognizer showing null in iOS SWRevealViewController

I wan't to use SWRevealViewController in my application for that i follow steps as per given link "https://www.youtube.com/watch?v=5SUV1YY2yxQ".

But my application get crashed at this line

[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

Complier showing following error

terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'.

Please check my story board design

attached is my story board design--- here Reveal View Controller is my initial view from this view connection segue 1 for left menu list (Simple view controller table view added programmatically) 2 for subclass of navigation controller and view controller is my root view controller..after submitting right credential application push next view i.e. Dashboard six option view controller (which has blue background)

DashBoardSixOptionViewController

Bellow are my Code for blue background view where i want to open reveal view controller .h file

#import <UIKit/UIKit.h>
 #import "SWRevealViewController.h"

@interface DashboardSixOptionViewController : UIViewController 
{

    SWRevealViewController *revealViewController;

}

@property (nonatomic,retain) SWRevealViewController *revealViewController;
@end

.m file

@interface DashboardSixOptionViewController ()

@end

@implementation DashboardSixOptionViewController
@synthesize revealViewController = _revealViewController;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"gesture desc::%@",self.revealViewController.panGestureRecognizer);


    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
-(void)configureView
{
 [self.navigationController.navigationBar setTintColor:[UIColor orangeColor]];

    CGRect dashboardNavFrame = self.navigationController.navigationBar.bounds;
//    dashboardNavFrame.size.height += 5;

    self.toolBar = [[UIToolbar alloc] initWithFrame:dashboardNavFrame];

    [self.toolBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

    [self.toolBar setTintColor:[UIColor redColor]];


    //disable any back btn
    self.toolBar.clearsContextBeforeDrawing = NO;
    self.toolBar.clipsToBounds = NO;
    [self.toolBar setTag:700];

    NSMutableArray *buttons = [[NSMutableArray alloc] init];


    UIImage *imgOption;

    imgOption = [UIImage imageNamed:@"imgOptionsIOS7.png"];

    UIButton *aOptionButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [aOptionButton setEnabled:NO];
    aOptionButton.frame = CGRectMake(0, 0, imgOption.size.width, imgOption.size.height);
    [aOptionButton setImage:imgOption forState:UIControlStateNormal];
//    [aOptionButton addTarget:self action:@selector(showLeftMenu:) forControlEvents:UIControlEventTouchUpInside];
    [aOptionButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];


    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:aOptionButton];
    [btn setTarget:self.revealViewController];
    [btn setAction:@selector(revealToggle:)];
    [buttons addObject:btn];
  [self.toolBar setItems:buttons animated:YES];

    [self.navigationController.navigationBar addSubview:self.toolBar];

}

from view controller DashboardSixOptionView view push programatically below is my code

DashboardSixOptionView  = [mainStoryboard instantiateViewControllerWithIdentifier:@"DashboardStoryBoardWithSixOption"];
    DashboardSixOptionView.arrTableViewHreaders = self.arrForMenuOption;
    [self.navigationController pushViewController:DashboardSixOptionView animated:YES];

Please help me out why i getting crash.

Thanks in advanced Priyanka

Upvotes: 1

Views: 921

Answers (3)

Akshay
Akshay

Reputation: 179

I was having the same problem !! If you want to connect to menu view controller you have to connect it through swrevealviewcontrtoller so check your segues once again and this solved my issue and I used.

[self.revealviewcontroller pangesturerecogonizer];

Instead of

[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

Upvotes: 0

Dayanithi Natarajan
Dayanithi Natarajan

Reputation: 843

Don't create the new object for SWRevealViewController in DashboardSixOptionViewController.h or DashboardSixOptionViewController.m file. Instead of it, use the same object which is created in SWRevealViewController class.

DashboardSixOptionViewController.m Class

#import "SWRevealViewController.h"
-(void)viewDidLoad{
_barButton.target = self.revealViewController;
_barButton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];
}

Upvotes: 0

user580175
user580175

Reputation:

I'm guessing that self.revealViewController.panGestureRecognizer is nil, because you created a property for the SWRevealViewController but didn't assign any value in viewDidLoad.

Have you set all the classes properly in your Storyboard?

Plus, why do you use @synthesize and a class variable for your SWRevealViewController? There is no need anymore to do that.

I recommend you to take a look to this great tutorial for SWRevealViewController.

Upvotes: 1

Related Questions