1

In my project I have a Slide Menu with 3 options in a TableView. Depending of the selected option I want to segue to the ViewController1,ViewController2 or ViewController3 all them preceded by a navigation controller.

Currently I'm using a segue in the Storyboard from the Prototype Cell to the ViewController1 with "segueid" as identifier, so all the options segue to ViewController1.

That's the code in the file.swift to prepare the segue:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "segueid"{
        var DestViewController = segue.destinationViewController as! UINavigationController}}

The problem comes when XCode only allows me to set one segue from the cell in the Storyboard so I can't point VC2 and VC3.

Is there any way to segue to different views preceded by a navigation controller depending of the selected row from the tableview?

Victor Rius
  • 4,566
  • 1
  • 20
  • 28

2 Answers2

2

You should create your segues between viewcontrollers.

Do not create segue from cell to viewcontrollers.

Then after you select a cell you should decide which segue you would like to invoke.

meda
  • 45,103
  • 14
  • 92
  • 122
  • 1
    That worked perfect! Now I added the code pasted below to didSelectRowAtIndexPath to choose the right segue. Thanks! `performSegueWithIdentifier("segue_" + listOfOptions[indexPath.row].optionName, sender: nil)` – Victor Rius Feb 05 '16 at 20:14
1

I think it will help you out. Download the source code from this link. Its AKSwiftSlideMenu for iOS AKSwiftSlideMenu

It has a method in BaseViewController in which you can set your selected viewcontroller instantiated from storyboard as root view controller of self.navigationController.

func slideMenuItemSelectedAtIndex(index: Int32) {
        let topViewController : UIViewController = self.navigationController!.topViewController!
        print("View Controller is : \(topViewController) \n", terminator: "")
        switch(index){
        case 0:
            print("Home\n", terminator: "")
            break
        case 1:
            print("Play\n", terminator: "")
            break
        case 2:
            print("Camera\n", terminator: "")
            break
        default:
            print("default\n", terminator: "")
        }
    }
Shehzad Ali
  • 1,846
  • 10
  • 16