0
votes

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.

3

3 Answers

3
votes

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];
0
votes

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?

0
votes

Use this simple NSNotificationCenter example. Works a charm!