Reputation: 1
Novice question. I'm building an app and I want to call a method that I've declared in a ViewController - from the AppDelegate (on applicationDidBecomeActive).
So basically, In TestAppDelegate.m I have...
- (void)applicationDidBecomeActive:(UIApplication *)application { // I want to call a method called "dothisthing" that I've defined in FirstViewController.m // This does not work: [FirstViewController dothisthing] }
In FirstViewController.m I have...
- (void) dothisthing { NSLog(@"dothisthing"); }
This is my first iPhone app, so any help would be appreciated.
Upvotes: 0
Views: 3000
Reputation: 3831
Use this simple NSNotificationCenter
example. Works a charm!
Upvotes: 0
Reputation: 6814
The method is an instance method so you need to create the instance first and then call the method on the instance... or declare the method as static (+) instead of (-) before the void
FirstViewController* controller = [FirstViewController alloc];
[controller dothisthing];
[controller release];
Upvotes: 3
Reputation: 33345
you could also create a notification in the FirstViewController, to have that method called when your application becomes active.
There is a similar question where I have posted the code snippets for that option
How to refresh UITableView after app comes becomes active again?
Upvotes: 0