0

I have done some searching on this but can't seem to find an answer that's applicable to my issue.

In my app a user can create a Team. This is a 3 VC process that STARTS from the Manage Teams VC by pressing +. Once the team creation is complete, I want the app to go back to the Manage Teams VC without any reference to where it's been. Example of WHAT I DONT WANT: if I create a Segue from CreateTeamStep3 back to Manage Teams and perform it, Manage Teams VC will now receive a Back button allowing the user to go back to step 3.

The app is a Tab Bar application with Navigation Controllers embedded into each tab.

Here's a rough breakdown:

Tab Bar
    - Newsfeed (embedded nav)
      -- Newsfeed detail
    - Teams (embedded nav)
      -- Team detail
    - Find (embedded nav)
      -- Found Detail
    - More (embedded nav)
      -- Manage Teams
         --- Create a Team Step 1
         --- Create a Team Step 2
         --- Create a Team Step 3
      -- Etc...

I've tried stuff like

var storyboard = UIStoryboard(name:"Main", bundle: nil)
var vc: AnyObject! = storyboard.instantiateViewControllerWithIdentifier("ManageSquadsVC") as UITabBarController
self.navigationController?.presentViewController(vc as UIViewController, animated: true, completion: nil)

But that just crashed the app.

matcartmill
  • 1,573
  • 2
  • 19
  • 38
  • "I want the app to go back to the Manage Teams VC **without any reference to where it's been**" .. "Manage Teams VC **will now receive a Back button allowing the user to go back to step 3.**" These are two contradictory statements. Please choose one. – Ian MacDonald Feb 03 '15 at 20:07
  • You are declaring `vc` as a `UITabBarController ` and then you want to present it as a `UIViewController `? Please choose one. – Cesare Feb 03 '15 at 20:12
  • @IanMacDonald How is that contradictory? Perhaps I didn't phrase the question correctly, or perhaps you didn't read it carefully. But I state that I want it to have no reference to where it's been, and then provide an example of what I've tried and how that couldn't work. – matcartmill Feb 03 '15 at 20:21
  • @CeceXX I removed the "as UITabBarController" part, thanks for catching that. Still crashes though. It says it had a fatal error: unexpectedly found nil when unwrapping an Optional value. I tried taking the navigationController? part but it still crashes. I'll do some more digging. – matcartmill Feb 03 '15 at 20:29
  • What is this line for? `var storyboard = UIStoryboard(name:"Main", bundle: nil).` You don't need it. – Cesare Feb 03 '15 at 20:31
  • You have to embed your "Managing Teams" VC in a `UINavigationController`. It seems like it's not embedded and XCode can't find it, thus crashing your app. – Armin Feb 03 '15 at 20:38
  • Your statement isn't clear; when you say "example", that leads me to believe that the statements that follow describe the behaviour you desire. – Ian MacDonald Feb 03 '15 at 20:38

2 Answers2

0

From my understanding you want to be able to get back to your "Manage Teams" VC at any of the steps (1,2, and 3).

You should present "Create a Team Step 1" modally (Make sure your "Manage Teams" is embedded in a UINavigationController) :

self.presentViewController(vc, true, nil)

and include a "Cancel" or "Return" button on all your "steps" that call:

self.dismissViewControllerAnimated(true, nil)

on the "Manage Teams" VC or the step VC itself.

enter image description here

Armin
  • 1,150
  • 8
  • 24
  • Ah, that makes a bit more sense, I guess, Question, though. How should I present my "Step 2" and "Step 3" VCs than? If I do a Push segue the app crashes because Push can only be done if the parent is a UINavigationController, which Step 1 will not be. As well, do you know if dismissing a modal VC performs the "viewWillAppear" function on the parent? – matcartmill Feb 03 '15 at 20:43
  • Also, is there anything preventing me from using an unwindSegue to do this? – matcartmill Feb 03 '15 at 20:50
  • Your "Step 1" needs to be embedded in a separate `UINavigationController` as well! I think you should actually present the `UINavigationController` that has a `rootView` connection to "Step 1". I have updated my answer with the storyboard. – Armin Feb 03 '15 at 21:14
  • Unwind Segue is for when you want to go back to Step 1 directly from Step 3. For your use case (Adding a new team, and dismissing the whole thing) I suggest a modal representation. – Armin Feb 03 '15 at 21:17
  • Thanks for that. What I ended up doing was just doing an unwindSegue, which achieves the result I'm looking for without having to redo my storyboard. I appreciate the suggestion though! – matcartmill Feb 03 '15 at 21:20
  • The Unwind Segue works well because I'm only calling it once the steps are completed. Otherwise the "Back" button will allow the user to go to the previous steps on each VC. – matcartmill Feb 03 '15 at 21:22
  • I see. Ok, glad you found the answer. – Armin Feb 03 '15 at 21:23
0

Though there were a couple of good options mentioned, I ended up using an Unwind Segue. This allowed me to go back to the "Manage Teams" page and not have to worry about the Nav Controller being given a back button to Step 3.

I followed this guide to implement the Segue: Unwind Segue

Community
  • 1
  • 1
matcartmill
  • 1,573
  • 2
  • 19
  • 38