I'm trying to use the AppDelegate to trigger a delegate method in the viewcontroller via and NSTimer. So in the AppDelegate, I basically have:
AppDelegate.h
@protocol TestDelegate <NSObject>
-(void)testFunction:(NSString *)testString;
@end
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) id<TestDelegate> testDelegate;
...
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
self.timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(trigger:)
userInfo:nil
repeats:YES];
return YES;
}
-(void)trigger:(id)sender {
[self.testDelegate testFunction:self];
}
In my view controller I have:
ViewController.h
@interface ViewController : UIViewController <TestDelegate>
@property (nonatomic, strong) AppDelegate *appDelegate;
@end
ViewController.m
@implementation ViewController
...
-(void)viewDidLoad {
self.appDelegate = [[UIApplication sharedApplication] delegate];
self.appDelegate.testDelegate = self;
}
-(void)testfunction:(NSString *)testString {
NSLog(@"%@", testString);
}
@end
when I load the ViewController in my app, nothing happens? I know the NSTimer is successfully firing, but the delegate method isn't being triggered.