3

I have implemented the SWRevealViewController into my app to give my app a nice side menu. My main (home) screen for the app is TableViewController.swift - this is also the only place you can access the side menu from. The side menu all works perfectly. Here is an image to show what it looks like:

enter image description here

The 5 options you can see in the menu, are created in a tableView I want them to all link to other view controllers. I have currently achieved this using the method they showed in the tutorial for this side menu, which is to create a segue of reveal view controller push controller. This all works.

The problem

When you press one of the options, It reveals the new view controller as the sw_front, therefore, I have lost access to the main (home) screen. For example, the VC linked to the first option 'Films I want to see' is just a plain green VC. The image below shows what happens after I have pressed that option and then tried to go back:

enter image description here

So you can see, the VC that appears at the front is no longer my main (home) screen.

I'd like to know is there away I can set this up so when you press an option in the side menu, it opens up the new VC over the top of the side menu, so when you close down that VC, it still shows the side menu open with the Main (home) screen in front.

I hope that makes sense. Please ask if you need to see any of my code.

Brian
  • 14,610
  • 7
  • 35
  • 43
Nick89
  • 2,948
  • 10
  • 31
  • 50

1 Answers1

3

I managed to find a solution!

  1. I first created my 5 new view controllers (one for each option in the side menu)

  2. I then linked each cell to it's view controller by creating a 'Show' segue. So my storyboard now looked like this:

enter image description here

  1. I created a segue identifier for each segue.

Then in my sideMenu.swift file, I added the following:

  1. Created variables to store the identifiers for the segues.

    // Mark:- Sets the side menu segue identifiers
    let smOption_One = "toFilmsIWantToSee"
    let smOption_Two = "toSearchForAnyFilm"
    let smOption_Three = "toMeetTheTeam"
    let smOption_Four = "toContactUs"
    let smOption_Five = "toTermsOfUse"
    
  2. I then added the didSelectRowAtIndexPath method, and added performSegueWithIdentifier for each of my segues.

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
    self.performSegueWithIdentifier(smOption_One, sender: indexPath)
    self.performSegueWithIdentifier(smOption_Two, sender: indexPath)
    self.performSegueWithIdentifier(smOption_Three, sender: indexPath)
    self.performSegueWithIdentifier(smOption_Four, sender: indexPath)
    self.performSegueWithIdentifier(smOption_Five, sender: indexPath)
    
    }
    
  3. And finally, added the prepareForSegue method. Inside this method I did a check for each identifier, and then segued to the destinationViewController.

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    
    if segue.identifier == smOption_One {
    
        segue.destinationViewController as! FilmsIWantToSeeViewController
    
    } else if segue.identifier == smOption_Two {
    
        segue.destinationViewController as! SearchForAnyFilmViewController
    
    } else if segue.identifier == smOption_Three {
    
        segue.destinationViewController as! MeetTheTeamViewController
    
    } else if segue.identifier == smOption_Four {
    
        segue.destinationViewController as! ContactUsViewController
    
    } else if segue.identifier == smOption_Five {
    
        segue.destinationViewController as! TermsOfUseViewController
    
    }
    
    }
    

This perfectly creates a segue to the correct view controller, depending on which option I press, and presents it over the top of the side menu, so when I dismiss that view controller, it still shows me the side menu, and therefore allows me to get back to my main screen.

Not sure if there is an easier way of doing this, but it certainly works how I needed it to. Written in Xcode 7.2 with Swift 2.

Nick89
  • 2,948
  • 10
  • 31
  • 50