Calling UIViewController method from app delegate

Solutions Collect From Internet About “Calling UIViewController method from app delegate”

  1. Notification. But you don’t want this.
  2. You can get the reference to your that viewController in the AppDelegate. Than call that (void)goToBeginning method in the (void)applicationDidEnterBackground

For example: In your ViewController

- (void)viewDidLoad
    [super viewDidLoad];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.myViewController = self;

And in your AppDelegate:

@class MyViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (weak, nonatomic) MyViewController *myViewController;


And in the AppDelegate‘s implementation:

- (void)applicationDidEnterBackground:(UIApplication *)application
    [self.myViewController goToBeginning];