0
votes

Ive built a side menu that pop out when you click on a bar button item, After you click on one of the menu options the view controller load up with the right data but the bar button item is disappeared. so i made some research and i found out that the problem is my segue destination, My segue destination is the view controller and not the navigation controller so i try to change my code ending up with this:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        if let cell = sender as? UITableViewCell{
            let i = tableView.indexPath(for: cell)!.row
            if segue.identifier == "viewController"{

                let nav = segue.destination as! UINavigationController
                let addEventViewController = nav.topViewController as! ViewController

                addEventViewController.varView = i
                }  
            }
        } 

And now i'm getting this error:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

My storyboard: enter image description here

2
Get rid of those ! Use conditional casting and the debugger to see what isn't what you think it is.Paulw11
On which line do you get this error?Ahmet Sina
@AhmetUstem in this line let nav = segue.destination as! UINavigationControllerBen Shabat
You probably won't be able to use segues to build a side menu. You will probably just have to manipulate the view hierarchy as required. You could make your main view controller a container view and just set the active view controller into thatPaulw11
You edited the question and changed it to something completely different - people already wrote answers and comments to your question and now their answers are no longer relevant. You should revert your edits and open a NEW question.Moshe Gottlieb

2 Answers

0
votes

Please update your code as below. Here sharedAppdelegate() is shared instance of appdelegate

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if let cell = sender as? UITableViewCell{
        let i = tableView.indexPath(for: cell)!.row
        if segue.identifier == "viewController"{

            let yourDestinationController = segue.destination as! ViewController
            let nav = UINavigationController.init(rootViewController: yourDestinationController)
            let win = AppDelegate.sharedAppdelegate().window
            win.rootViewController = nav
            win?.makeKeyAndVisible()
            addEventViewController.varView = i
            }  
        }
    } 

In your Appdelegate add below method

 static func sharedAppdelegate() -> AppDelegate
{
    return UIApplication.shared.delegate as! AppDelegate
}
0
votes

I think the problem is that you call segue from your BackTableVC and there is no segue to the navigation controller, only to the controller that is placed bottom right in your storyboard. You either have to perform the segue on RevealViewController or relink the segue so it leads to the navigation controller.