0

I have the mainstoryboard + viewcontroller

When I press a button on the mainstoryboard it will show another storyboard.

When I press a button in the new storyboard I want to call a function of the mainstoryboard.

How can I make this happen?

NobodyNada
  • 7,529
  • 6
  • 44
  • 51
  • 2
    You should look into your design and figure out *why* you need to call a method on a viewController that is no longer visible. Maybe this function can be pulled out into separate class. – quark Nov 04 '14 at 21:25
  • Using protocols is the usual pattern for communication with controllers lower in the stack. – Abizern Nov 06 '14 at 19:51

2 Answers2

0

You can grab the storyboard and instantiate a viewController from it like this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"yourStoryboardName" bundle:nil];
YourViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerIdentifier"];

But if you require a function that contains the context of the previous view controller, you should keep a reference to it and just call your methods directly from there. You can also use the presentingViewController property to access the view controller that started the modal presentation. Or if using a navigationController you can use the viewControllers property to access previous viewControllers in the stack.

Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
0

The comment of Abizem gave me the right tag to search for.

'Protocols'.

I found a very good explanation here on stackoverflow.

Look there: How to access a previous story board.

Just have a look at the answer of Matt Price. Very nice explanation!

Community
  • 1
  • 1