Segue from tableview to view preceded by navigation controller

不打扰是莪最后的温柔 提交于 2019-12-11 10:18:23

问题


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?


回答1:


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.




回答2:


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: "")
        }
    }


来源:https://stackoverflow.com/questions/35232018/segue-from-tableview-to-view-preceded-by-navigation-controller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!