-1

When my app will enter foreground, I need to call some methods of my view controller from the app delegate class. How is the best way to realise it?

I try to create a "fake" notification in "applicationWillEnterForeground" method:

[NSNotificationCenter defaultCenter]postNotificationName:@"test" object:nil];

And add observer in view controller:

[self addObserver: self selector:@selector(testMethod) name:@"test" object:nil];

Is this OK? Another method there: Calling UIViewController method from app delegate

Which approach is better and why?

PS Sorry for my bad english.

1

2 Answers 2

0

Quick Answer:

  1. Yes, that should work with your "fake" notification
  2. But why should you do so? You could let your viewController do all the things without die AppDelegate -> just call your methods, that you want to be done in the 'viewDidLoad'-method of your viewController. (I assume, your viewController is the entry point of your App)
Sign up to request clarification or add additional context in comments.

1 Comment

Load-time is not the only time an app will enter foreground.
0

Notification will support many destinations, whereas the answer here only supports one viewController being told what to do.

On the other hand, calling directly through a reference is easier to understand and to debug.

I don't understand why you call it a "fake" notification - this is exactly how that call is meant to be used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.