NSTimer调用方法导致线程断点

时间:2013-07-31 11:26:27

标签: objective-c

运行下面的类在NSTimer对象[timer]调用的@selector方法timerEvent的第一次运行结束时给出一个断点。给出的错误是__NSFCTimer,'<错误:未知类>'。在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

0 个答案:

没有答案