What this error is "+[NSTimer scheduledTimerWithInterval:target:selector:userInfo:repeats:]: unrecognized selector sent to class 0x1c864a0' "?
I am writing a simple code that is using NSTimer, but getting error as followed
"+[NSTimer scheduledTimerWithInterval:target:selector:userInfo:repeats:]: unrecognized selector sent to class 0x1c864a0'"
my Code is
-(void)myTimerMethod {
NSLog(@"myTimerMethod is Called");
myTimer = [NSTimer scheduledTimerWithInterval: 1.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];
}
-(void)开发者_Python百科 targetMethod:(NSTimer*) theTimer {
NSLog(@"Me is here at 1 minute delay");
}
and I am making object of of Timer class in my appDelegate.m like as following
Timer *myTimer = [[Timer alloc] init];
[myTimer myTimerMethod];
What is the problem in it?
the method is misnamed as declared. it is:
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
This code perfectly working, check it out, just copy and paste the code.
@implementation Timer
-(void)myTimerMethod { NSLog(@"myTimerMethod is Called"); [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES]; }
-(void) targetMethod:(NSTimer*) theTimer { NSLog(@"Me is here at 1 minute delay"); }
@end
In app delegate call
Timer *myTimer = [[Timer alloc] init];
[myTimer myTimerMethod];
精彩评论