Matrix1123 2018-02-03 16:11 采纳率: 100%
浏览 1076
已采纳

objective-c中使用NSTimer如下语句为何没有输出?

NSInteger _count;
NSTimer* _timer;

  • (void)tel{ NSLog(@"正在打第%ld个电话",_count++); if(_count>10){ NSLog(@"定时器关闭"); [_timer invalidate]; } }
  • (void)timerTest{ _timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(tel) userInfo:nil repeats:YES]; } main函数中创建对象xxx,然后调用[xxx timerTest];为何什么输出都没有? 我是在command line tool中写的,不是ios项目,不知道是不是这个原因
  • 写回答

3条回答 默认 最新

  • oyljerry 2018-02-04 01:48
    关注

    timer需要有消息循环。UI线程等调用

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?