0

This question relates to:

I understand this question might be very similar to others. But I have been unable to use some of the answers to solve my issue.

Here is how my storyboard looks:

enter image description here

The viewController has a segmentControl that controls two viewControllers. I now want to segue to the DetailViewController, but it is appearing as modal segue which hides the tabBar and navigationBar.

I have tried deleting and recreating the segue as the some off the answers have suggested but it doesn't solve anything. Is there anything someone could suggest me or direct me to?

Edit:

After testing out the demo that the pod provides I was able to outline the issue I am struggling with. I have implemented the same methods in which it is practically identical. The only difference is that my method for this PageMenu does not use nib files like the demo has done.

In my tableView delegate I am trying to pass a recipe data to the DetailView. This is how my prepareForSegue and didSelect looks:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    performSegue(withIdentifier: "detail", sender: recipe)

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "detail" {
        let vc = segue.destination as! DetailViewController
        let indexPath = tableView.indexPathForSelectedRow!
        vc.recipe = RecipeManager.shared.recipes[indexPath.row]

    }
}

Here is the demo's didSelect:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let newVC : UIViewController = UIViewController()
    newVC.view.backgroundColor = UIColor.white
    newVC.title = "Favorites"

    parentNavigationController!.pushViewController(newVC, animated: true)
}

When comparing it with the demo I am struggling to understand where to implement the parentNavigationController!.pushViewController(newVC, animated: true) which I believe will solve my issue.

Chace
  • 561
  • 10
  • 28
  • What do you mean by *"The viewController has a segmentControl that controls two viewControllers."*? Are you using it to load one or the other table view into a container view? – DonMag Jun 19 '17 at 18:04
  • are you trying to push viewcontroller embedded in UINavigationController on another UINavigationController? – Suhit Patil Jun 19 '17 at 18:10
  • @DonMag Basically I'm using a pod called 'PageMenu' which uses a viewController to perform segmented actions where you can slide to different pages, like you'd see on Instagram. – Chace Jun 19 '17 at 18:10
  • @suhit Not sure what you mean. I only have one UINavigationController as you can see. All I'm trying to do is segue to the DetailViewController. – Chace Jun 19 '17 at 18:12
  • @Chace - ok... most likely, your "PageMenu" pod is causing your segue to be placed *outside* of the Navigation Controller's stack. You need to figure out how the view hierarchy is arranged, and make sure the segue to `DetailVC` is being done ***from*** `ViewController` and not from a child VC as part of "PageMenu" – DonMag Jun 19 '17 at 18:17
  • @DonMag I understand. But I can't really think of way round it. There's nothing on the documentation which supports this scenario. – Chace Jun 19 '17 at 18:23
  • @Chace - I assume you're talking about this? https://github.com/PageMenu/PageMenu ... and you want to actually navigate *away* from that, staying in the NavController but removing the whole PageMenu labels/tabs structure? (and are you using Swift or Obj-C ?) – DonMag Jun 19 '17 at 18:27
  • @DonMag Yes, I am referring to that pod. Yes, you're correct I want to navigate to the DetailView. I am not sure if I need to remove PageMenu labels/tabs but if that is required then I don't mind. Looking at their demo example they also accomplished this in the `PageMenuDemoSegmentedControl`. – Chace Jun 19 '17 at 18:35
  • Well, your options are 1) Figure out how to get the segue to *replace* the current "Page" in the PageMenu structure, or 2) Use Delegate Protocol pattern to "call back" to your ViewController code to push DetailView onto the stack. Either way may end up being a little confusing for the user though, as you'll be using "non-typical" navigation. – DonMag Jun 19 '17 at 18:41
  • @DonMag I've been looking t the Demo app that the pod provides. It has a `var parentNavigationController : UINavigationController?` which I'm not entirely sure what is responsible for, but I believe it relates to the subject matter. – Chace Jun 19 '17 at 19:25
  • I've tried implementing it but I receive an error saying "Application tried to present modally an active controller .'" – Chace Jun 19 '17 at 19:35
  • The `PageMenuDemoSegmentedControl` demo included looks like it does *exactly* what you're trying to do... – DonMag Jun 19 '17 at 19:38
  • @DonMag Please see my updated answer :) – Chace Jun 19 '17 at 20:05

1 Answers1

1

Assuming you implemented the parentNavigationController as they did in the demo, you are almost all set.

Delete your existing Segue - you won't be using it.

Give your DetailViewController a Storyboard ID - such as "DetailVC"

Change your code to instantiate the DetailVC and push it onto the parent Nav Controller

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if let vc = self.storyboard?.instantiateViewController(withIdentifier: "DetailVC") as? DetailViewController {
        vc.recipe = RecipeManager.shared.recipes[indexPath.row]
        parentNavigationController!.pushViewController(vc, animated: true)
    }

}
DonMag
  • 69,424
  • 5
  • 50
  • 86
  • Thank you for this, it worked perfectly! I was just wondering, is there a way to also hide the tabBar the same way the navBar gets replaced, or is this a different question all together. – Chace Jun 19 '17 at 20:50
  • Not sure exactly how your navigation hierarchy is designed, but there are several ways to hide a tab bar. Take a look at some of the answers here: https://stackoverflow.com/questions/37040313/hiding-the-tabbar-and-removing-the-space ... if that doesn't work for your situation I expect you can find something via search. – DonMag Jun 19 '17 at 21:01