ashwin shrestha
ashwin shrestha

Reputation: 107

SWRevealViewController close left side view when navigation back button pressed

I have a front view controller and a slide side view.. On navigation bar back button pressed, I have been poping the viewcontroller, to previous view controller. I want my side view to slide out, if it was open when i press back button.

My code is I have a navigation bar with a back button as :

 [navbar.backViewButton addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];

On back button press:

-(void)backBtnClicked{
[self.navigationController popViewControllerAnimated:YES];
}

I know I can add revealtoggle as:

-(void)backBtnClicked{
[self.revealViewController revealToggleAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
}

But this gives me a problem, if the side view was closed previously, it toogles and open it, and that is something i don't want on pressing the back button.

I want something like

-(void)backBtnClicked{
 if([self.revealViewController isSideViewAppeared or isSideviewShowing]){     
[self.revealViewController revealToggleAnimated:YES];
}
[self.navigationController popViewControllerAnimated:YES];
}

Help needed.. Thanks in advance

Upvotes: 1

Views: 2294

Answers (5)

phani
phani

Reputation: 130

Use this code at button action.

if (self.revealViewController.frontViewPosition == 4){

            [self.revealViewController revealToggleAnimated:YES];
}

Upvotes: 0

javimuu
javimuu

Reputation: 1859

To close the Slide-Menu manually when using SWRevealViewController let's try it: self.revealViewController().revealToggle(animated: true)

Upvotes: 0

user3432164
user3432164

Reputation:

You have to use SWRevealViewController navigation method for pop and push.

Write this code into your back button action method.

  UINavigationController *frontNavigationController = (id)revealController.frontViewController;
        if ([frontNavigationController.topViewController isKindOfClass:[YourViewController class]] )        
          viewwaboutus=[[FlashViewController alloc]init];

            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewwaboutus];
            [revealController pushFrontViewController:navigationController animated:YES];
        }

May be it will help you.

Upvotes: 0

ashwin shrestha
ashwin shrestha

Reputation: 107

I have found the answer, I was just trying to toogle the sideview appear and disappear as :

[self.revealViewController revealToggleAnimated:YES];

which was toggling the leftview on and off.. simple solution was

-(void)backBtnClicked{


[self.revealViewController rightRevealToggleAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
}

Upvotes: 1

beyowulf
beyowulf

Reputation: 15331

Create a bool property that stores whether it's open or closed. In viewWillAppear open or close it based on said property.

Upvotes: 0

Related Questions