NSTimer在哪个线程中创建就在哪个线程中运行。只有把创建的NSTimer对象放入当前线程的已经启动的RunLoop中定时器才能运行。
可以通过[NSRunLoop currentRunLoop]来获取当前线程的RunLoop,RunLoop在主线程中默认是开启的,而在子线程中默认是关闭的,需要手动启动RunLoop。
使用scheduledTimerWithTimeInterval方法创建的NSTimer会自动加入到当前RunLoop中,RunLoop的mode为默认的;而使用timerWithTimeInterval方法创建的NSTimer需要手动添加到当前RunLoop中并指定其mode。
NSTimer在哪个线程中创建就在哪个线程中运行。只有把创建的NSTimer对象放入当前线程的已经启动的RunLoop中定时器才能运行。
可以通过[NSRunLoop currentRunLoop]来获取当前线程的RunLoop,RunLoop在主线程中默认是开启的,而在子线程中默认是关闭的,需要手动启动RunLoop。
使用scheduledTimerWithTimeInterval方法创建的NSTimer会自动加入到当前RunLoop中,RunLoop的mode为默认的;而使用timerWithTimeInterval方法创建的NSTimer需要手动添加到当前RunLoop中并指定其mode。