Search code examples
iosuiviewcontrolleruiapplicationdelegate

In App Delegate call method from another class


I have a view which contains scroll view with some subviews (UIViewControllers). I want to call a method (stop timer) from a class, one of their UIViewControllers, in applicationWillResignActive: method of App Delegate.

What's the best way to implement this?


Solution

  • Don't worry about handling that event in your app delegate and passing it on. Just register for a notification in whatever class you're interested in handling the event from:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(someMethod:)
                                                 name:UIApplicationWillResignActiveNotification
                                               object:nil];