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?
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.
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: "")
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.