19

I am trying to implement a SideBar / slide out menu using the SWRevealViewController. I have a bunch of menus. One of the menu is to get app version info. So When I click on the cell, An AlertView displays the version number and on pressing the OK button I would like to close/hide the SideBar menu and return to the pervious view(front controller). For example, if I am on log in controller and I press the settings button to reveal the side bar and I choose version menu from TableView cells, a pop will open displaying version# and when I press Ok, the SideBar should close and return to the login screen without me having to tap the settings button again or swiping to return. How can I return to the login screen when I press OK on the alert view.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    // the user clicked OK
    if (buttonIndex == 0) {

      //close the side bar and return to front view controller
    }
}
Alap Anerao
  • 2,083
  • 22
  • 27
moni_sind
  • 605
  • 1
  • 5
  • 15
  • I have the same issue. I have menu **Exit** with alert YES / NO. When pressing NO I need to go back to the same menu. I remember last called `segue` (menu) and I call it again. – new2ios May 28 '15 at 09:06

6 Answers6

35

I just figured out the answer. I just use the following code to hide the side bar.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
   if (buttonIndex == 0) {
    [self.revealViewController revealToggleAnimated:YES];

   }
}
moni_sind
  • 605
  • 1
  • 5
  • 15
16

The correct answer is:

self.revealViewController().revealToggle(animated: true)
Nupur Sharma
  • 1,106
  • 13
  • 15
  • 1
    Firt yo must to check if your menu is open -> if (revealViewController().frontViewPosition == FrontViewPosition.right) – kike0kike Jun 09 '17 at 11:39
11

If anyone is looking for a swift version, just use this single line:

self.revealViewController().revealToggleAnimated()
Alap Anerao
  • 2,083
  • 22
  • 27
2

if the sidebar on left using:

    self.revealViewController().revealToggle(animated: true)

if was on the right using:

    self.revealViewController().rightRevealToggle(animated: true)
aqeel
  • 153
  • 1
  • 2
  • 11
0

Control it if it opened, if so close

if (self.revealViewController().frontViewPosition != FrontViewPosition.left) {
                    self.revealViewController?.revealToggle(animated: true)
                    
      }
Ucdemir
  • 2,852
  • 2
  • 26
  • 44
-1

//View Did load add this // Swift 4.2

func viewDidLoad() {

super.viewDidLoad()
let leftMenuItem = UIBarButtonItem(image: UIImage(named: "menu"), style: .plain, target: revealViewController, action: #selector(SWRevealViewController.revealToggle(_:)))
navigationItem.setLeftBarButton(leftMenuItem, animated: true)

}
Nazik
  • 8,696
  • 27
  • 77
  • 123