运行下面的类会在 NSTimer 对象 [ timer ] 调用的 @selector 方法 timerEvent 的第一次运行结束时产生线程中断。给出的错误是 __NSFCTimer, '<error: unknown class>'。在 currentNumber 到 1 的第一次迭代后,它似乎崩溃了。
有任何想法吗?
//
// NumberLooper.m
// delegation excersise
//
// Created by Edwin on 7/31/13.
// Copyright (c) 2013 Offbeat Software. All rights reserved.
//
#import "NumberLooper.h"
@implementation NumberLooper
-(void) timerEvent: (NSTimer *)timer {
if (currentNumber < 256)
currentNumber ++;
else
currentNumber = 0;
NSLog (@"%d", currentNumber);
[self.delegate numberHasChangedTo:currentNumber];
}
-(void) startTimerLoop {
if (!timer) {
timer = [NSTimer scheduledTimerWithTimeInterval: 0.020 target:self selector:@selector(timerEvent:) userInfo:nil repeats:YES];
NSLog(@"The timer has started");
}
else
{
NSLog(@"The timer is already running");
}
}
@end