Reputation: 3234
I have following code written to run NSTimer
. But the NSTimer selector is not getting called.
.h file
@interface XViewController : UIViewController {
NSTimer *repeatServerRequest;
}
@property(nonatomic, retain) NSTimer *repeatServerRequest;
- (void)checkForMinimunOnetimePinEntry;
- (void) initializeTimer;
- (void)stopTimer;
.m file
@synthesize repeatServerRequest;
- (void)checkForMinimunOnetimePinEntry {
// some code
}
- (void) initializeTimer {
repeatServerRequest = [NSTimer scheduledTimerWithTimeInterval:15.0
target:self
selector:@selector(checkForMinimunOnetimePinEntry)
userInfo:nil
repeats:YES];
}
- (void)stopTimer {
[repeatServerRequest invalidate];
[repeatServerRequest release];
repeatServerRequest = nil;
// [self.repeatServerRequest invalidate];
// [self.repeatServerRequest release];
// self.repeatServerRequest = nil;
}
What am I doing wrong?
Also answer me which one is right to use: self.repeatServerRequest or simply repeatServerRequest?? Thanks in advance!
Upvotes: 0
Views: 691
Reputation: 11673
Do you have an init method for your class ? Perhaps you didn't put it in your code but I prefer to ask ...
Upvotes: 0
Reputation: 9593
The problem is that you assign timer to a class field, not a property.
To make this code working, just put self.
before repeatServerRequest =
.
When you use self.repeatServerRequest
, compiler invokes [self setRepeatServerRequest:...]
and retains autoreleased timer.
Upvotes: 1