1
votes

Storyboard

I am having problems segueing to my detail view, using Navigation Controller.

I was using a tableview, to display some exercises, and when you clicked the exercise you would seque into the detail view, embedded in nav controller I have removed the Tableview, and added 3 buttons, each with its' own "show" segue to the detail view. It almost works, but it is now not using my Navigation controller, meaning that the view is just presented kind of like a modal presentation. I have tried removing the segue on one button and replace with this action:

@IBAction func strengthButton(_ sender: UIButton) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let destination = storyboard.instantiateViewController(withIdentifier: "ExerciseViewController") as! ExerciseViewController
    destination.componentaccessid = -1;
    destination.openedFromUrl = false;
    destination.exercise = self.strengthexercise
    destination.exercisetype = .strength
    self.navigationController?.present(destination, animated: true, completion: nil)
}

But that does exactly the same.

I have a prepare function:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let identifier = segue.identifier,
        let destination = segue.destination as? ExerciseViewController{
        destination.componentaccessid = -1;
        destination.openedFromUrl = false;
        switch identifier{
        case "strengthsegue":
            destination.exercise = self.strengthexercise
            destination.exercisetype = .strength
        case "rangesegue":
            destination.exercise = self.rangeexercise
            destination.exercisetype = .range
        case "combinedsegue":
            destination.exercise = self.combinedexercise
            destination.exercisetype = .combined
        default:
            print("Nothing")
        }

    }
}
2
self.navigationController?.pushViewControllerJuicyFruit
Doh, thank you. Why won't the segues show through nav controllercatu
check its kind in storyboard inspector, should be Show (e.g. Push)JuicyFruit

2 Answers

1
votes

Try this

self.navigationController?.pushViewController(destination, animated: true)
1
votes

In your code you are using,

self.navigationController?.present(destination, animated: true, completion: nil)

This will only present the UIViewController.

Instead use,

self.navigationController?.pushViewController(destination, animated: true)

to push the viewController in which the NavigationController is inherited.