iDeveloper
iDeveloper

Reputation: 941

UIButton not working on first touch and working on second touch ios

I am using SWRevealViewController to show right side menu. I am not using BarButtons but i have taken a normal button as my app dont have Navigation bar. The problem i am facing is when i touch that button the methods work properly but i cant see the menu bar coming in, and on second touch the side menu comes in. I am not able to figure out the issue. Help Much Appreciated. '

-(IBAction)btnMenuClicked:(id)sender
  {      
   SideMenuTableViewController *sidemenuController = (SideMenuTableViewController *)revealViewController.rightViewController;
   sidemenuController.pitcherArray = [nTimerArray mutableCopy];
   revealViewController.rearViewRevealWidth = self.view.bounds.size.width - 50;
    if (revealViewController)
     {
       [self.btnMenu addTarget:self.revealViewController action:@selector(rightRevealToggle:) forControlEvents:UIControlEventTouchUpInside];
       [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
       [self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];
     }
    [sidemenuController.tableView reloadData];
   }

'

Upvotes: 1

Views: 988

Answers (3)

Deepakraj Murugesan
Deepakraj Murugesan

Reputation: 1237

Import SWRevealViewController first

#import "SWRevealViewController.h"

Create a property for the button as follows...

@property (weak, nonatomic) IBOutlet UIButton *rearButton;

And in the ViewDidLoad method just use this code. It will help you with your problem.

- (void)viewDidLoad {
    [super viewDidLoad];
    SWRevealViewController *revealViewController = self.revealViewController;
    if ( revealViewController )
    {

        [self.rearButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
}

Upvotes: 2

garanda
garanda

Reputation: 1291

For me works if I remove the line of panGestureRecognizer

Upvotes: 0

viratpuar
viratpuar

Reputation: 554

remove tapGestureRecognizer. It might be work

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

Upvotes: 0

Related Questions