NSTimer crash with EXC_BAD_ACCESS in shared class
I have an NSTimer
running in a shared class. + (GlobalClass *)sharedInstance;
Basically it runs once, and the se开发者_如何转开发cond time it runs, it just killed the whole app.
This is how I'm doing the NSTimer
myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(moveMe)
userInfo:nil
repeats:YES];
method moveMe
is just an empty method for now. So it shouldn't be something that's happening within moveMe
.
Has anyone experienced this?
It looks like you're missing the colon in your selector name. The selector for NSTimer
takes an NSTimer
as an argument. Your code that creates the timer should look like this:
myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(moveMe:)
userInfo:nil
repeats:NO];
Note the colon after moveMe
. Your method should then look something like this:
- (void)moveMe:(NSTimer *)aTimer {
// Code
}
精彩评论