0

I have a ViewController that is embedded in a tab bar, but also accessed by pressing a button within one of the other ViewControllers. Only if it was triggered by another ViewController, I want a cancel button to appear.

On the ViewController containing the button, I've tried passing data by setting a variable in the newViewController, but since there's a NavigationController in the way, it won't let me access it. Is there a work-around for this?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
   let cancelsegue = segue.destinationViewController as! AddExerciseTableViewController
    cancelsegue.cancel = segue.identifier!
}

enter image description here

Stefan
  • 5,203
  • 8
  • 27
  • 51
user2179936
  • 455
  • 2
  • 7
  • 16
  • you do this the same way you would do this without a navigationcontroller in the way, 1. you over load the initializer by passing variables through inttializer injection, OR 2. you set up a publicly exposed method in the TAbie view controller so that when you initialize the tableview controller you call to that function or property before pushing or presenting the tableview contorller. OR 3. use delegation. What's the easiest in my opinion? The easiest is inejctiions using custom initializer. – Larry Pickles Nov 30 '15 at 20:30
  • How would I call the initialiser from that piece of segue code? – user2179936 Nov 30 '15 at 20:35
  • Take a look at this answer: http://stackoverflow.com/a/26951266/1630618 – vacawama Nov 30 '15 at 20:51

1 Answers1

1

If you want to refer to a view controller embedded in a navigation bar, you could try something like:

let destinationController = segue.destinationViewController.childViewControllers.first! as! SomeViewController

caseynolan
  • 1,236
  • 1
  • 9
  • 11